http Post : Send an XML document using RPGLE
Last Post 16 Mar 2012 01:31 AM by Dhanu Dhanu. 2 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Dhanu Dhanu
New Member
New Member
Posts:2

--
14 Mar 2012 10:44 AM
Hello,

I have to rewrite following java code using RPGLE which is basically send a xml file to httpPost request.
already installed the LIBHTTP library. Can I do this with httpapi? If so, which example should I study?


Thanks


            HttpClient client = new DefaultHttpClient();
           
            HttpPost post = new HttpPost("http://xx.xx.xx.xx/sms/send/bulk/sms.do");
            StringEntity se;
            String line  = null;
 
            try {
                  BufferedReader reader = new BufferedReader( new FileReader ("C:\\bulk.xml"));
                  StringBuilder stringBuilder  = new StringBuilder();
                  while( ( line = reader.readLine() ) != null ) {
                    stringBuilder.append( line );
                    se = new StringEntity( stringBuilder.toString(), HTTP.UTF_8 );
                    se.setContentType("text/xml");
                        post.setHeader("Content-Type","text/xml;charset=UTF-8");
                        post.setEntity(se);
                }
<!--Session data-->
Scott Klement
Editorial Staff Member
Editorial Staff Member
Posts:16361
Avatar

--
14 Mar 2012 11:15 AM

i'm not a Java expert, but I think you want this:

     H DFTACTGRP(*NO) ACTGRP('DHANU')
     H BNDDIR('HTTPAPI')

      /copy HTTPAPI_H

     D rc              s             10i 0
     D SendFile        s           5000a   varying
     D RecvFile        s           5000a   varying

      /free
        SendFile = '/path/to/bulk.xml';
        RecvFile = '/tmp/result.txt';

        rc = http_post_stmf( 'ht tp://xx.xx.xx.xx/sms/send/bulk/sms.do'
                           : SendFile
                           : RecvFile
                           : 30
                           : *omit
                           : 'text/xml;charset=UTF-8' );

        if rc <> 1;
           http_crash();
        endif;

        *inlr = *on;
      /end-free
EDIT: You'll have to remove the space between "ht" and "tp" in the above code snippet. I had to add it to keep the forum software from mangling the code.
Dhanu Dhanu
New Member
New Member
Posts:2

--
16 Mar 2012 01:31 AM
That is IT..... Thank you so much!!
You are not authorized to post a reply.

Acceptable Use Policy