[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

R: Re: Help on http_url_post() procedure



Hi Scott,
first of all I want to thank you for your answer and for your help.

I tried to get more information from the web server administrators, but I 
don't succeded in that.
They said I've only to do a POST request like this:
http://xxx.xxx.xxx.xxx:8080/axis2/WebService?data=xml message

However I modified my sorce as you suggested, sending my document by GET 
instead of POST.

D/copy qrpgcopy,httpapi_h                                                
                                                                         
D cmd             pr                  extpgm('QCMDEXC')                  
D  command                     200A   const                              
D  length                       15P 5 const                              
                                                                         
D enc             s                   like(HTTP_URL_ENCODER)             
D xml             s           1024a   varying                            
D target          s           1024a   varying   
                                                                         
D RESPONSE        c                   const('/tmp/response.xml')         
D TRACE           c                   const('/tmp/trace.txt')            
D CRLF            c                   const(x'0D25')                     
D HYP             c                   const(x'7D')                       
D URL             c                   const('http://xxx.xxx.xxx.xxx:8080/+ 
D                                            axis2/WebService?')         
D OK              c                   const(1)                           

 /free 
       
  xml = . . . ;
  http_debug(*ON:TRACE);                                                    
                                                                            
  enc = http_url_encoder_new();                                             
  http_url_encoder_addvar(enc : 'data' : %addr(xml)+2 : %len(%trimr(xml))); 
  target = URL + %trim(http_url_encoder_getstr(enc)); 
                                                                            
  if http_url_get(%trim(target) : RESPONSE) = OK;                           
     cmd('DSPF ' + HYP + RESPONSE + HYP : 200);                             
  endif;                                                                    
                                                                            
  *inlr = *on;                                                              
  return;                                                                   
                                                                            
 /end-free                                                                  

Great! Now WebService returns the response I expect!
Thanks a lot Scott!

But now I have some questions.

1. why they said I had to send XML document by POST method? 
In my "HTML simulator" I wrote "<form action="http://xxx.xxx.xxx.xxx:
8080/axis2/WebService" method=post>"

2. in some example you say http_url_encoder_getstr() is slower than 
http_url_encoder_getptr(). 
Is it possible to use the second one? Do you suggest to do that?

3. In the application we're developing, I'm required to store xml document 
(sent and received) in IFS. 
I think I have to compose xml as a string, store it as IFS stmf and send it 
after encoding.
In this way i'm sure that what I send and what I store are two different 
things.
There is a better way to do that?
Can I process directly a stmf? (I thought I could use http_url_post_stmf(), 
but now I know I've to use GET method)

Any other suggestion is welcome.
Thanks a lot again.
Eugenio

>----Messaggio originale----
>Da: sk@xxxxxxxxxxxxxxxx
>Data: 16-ago-2010 7.01
>A: "HTTPAPI and FTPAPI Projects"<ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
>Ogg: Re: Help on http_url_post() procedure
>
>Eugenio,
>
>Please understand that all web services are different.  We are not 
>familiar with your web service, and do not know how the data is supposed 
>to be sent -- therefore it's very difficult to answer your question.
>
>You say that you copy/paste it into a browser, adding ?data= and 
>pressing enter, and that works.   Hmmm... well, the browser is doing a 
>GET request, and you're asking HTTPAPI to do a POST request.  Perhaps 
>that's the problem??  Maybe this web service is expecting a GET request?!
>
>Also, you are not setting the content-type of the data for your POST 
>request.  For a GET request, there's no content-type... but for a POST, 
>you might have to set the content-type correctly.  As it stands, you're 
>taking the default, which would be wrong for a URL encoded HTML form 
>(which is what you appear to be sending.)   What does your web service 
>expect for a content-type?
>
>
>
>edlp1950@xxxxxxxxx wrote:
>> Hi,
>> I've a problem using http_url_post() function.
>> 
>> The Web Server expect an xml document in URL parameter 'data'.
>> 
>> I coded my RPG source as following
>> 
>> H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('HTTPAPI')                 
>>                                                                 
>> D/copy qrpgcopy,httpapi_h                                       
>>                                                                 
>> D cmd             pr                  extpgm('QCMDEXC')         
>> D  command                     200A   const                     
>> D  length                       15P 5 const                     
>>                                                                 
>> D enc             s                   like(HTTP_URL_ENCODER)    
>> D pointer         s               *                             
>> D size            s             10I 0                           
>> D xml             s           1024a   varying                   
>>                                                                 
>> D RESPONSE        c                   const('/tmp/response.xml')
>> D TRACE           c                   const('/tmp/trace.txt')   
>> D CRLF            c                   const(x'0D25')            
>> D HYP             c                   const(x'7D')              
>> D URL             c                   const(here I wrote server's URL
>> as a constant)              
>> * it's like this: http://ipAddress:port/axis2/WebService
>> D OK              c                   const(1)                  
>> 
>> /free                                    
>>                                           
>>   xml = // here I composed my xml document as a string,
>>         // without any separator between xml tags
>>         // or CRLF at end of lines.
>> 
>> http_debug(*ON:TRACE);                                                
>>                                                                        
>> enc = http_url_encoder_new();                                         
>> http_url_encoder_addvar(enc:'data' : %addr(xml)+2 : %len(%trimr(xml)));
>> http_url_encoder_getptr(enc : pointer : size);                        
>>                                                                        
>> if http_url_post(URL:        
>>                   pointer:                                       
>>                   size:                                          
>>                   RESPONSE) = OK;                                
>>     cmd('DSPF ' + HYP + RESPONSE + HYP : 200);                         
>> endif;                                                                
>>                                                                        
>> *inlr = *on;                                                          
>> return;                                                               
>>                                                                        
>> /end-free                                                              
>> 
>> 
>> Well, when I tried to send the document I received an xml response with an
>> error message.
>> It looks like 'data' parameter was missing or something causing
>> nullPointerException.
>> 
>> Reading the debug trace I found data I expect to be sent.
>> I found 'data=' followed by my xml document in encoded version.
>> I tried to send it directly from the browser (copying in the URL bar my 
url, 
>> '?
>> data=' and ecndoded xml)
>> It ran correctly and I received the response I expected.
>> 
>> Then I wrote this html form.
>> 
>> <form action="in this point I copied server's URL" method=post>
>> <fieldset>
>> <legend>Simulator</legend>
>> <br>
>> <br>
>> <br/>
>> Document<br/>
>> <textarea rows="5" cols="132" name="data">
>> here I copied my xml document in text format (I mean not encoded)
>> </textarea><br/>
>> <input type="submit" value="Enter">
>> </fieldset>
>> </form>
>> 
>> I sent my xml document opening xml page and pressing Enter.
>> It ran correctly again.
>> 
>> I think that the way I used HTTPAPI procedures is not correct.
>> Can anyone help me?
>> 
>> Thanks
>> 
>> Eugenio
>> 
>> -----------------------------------------------------------------------
>> This is the FTPAPI mailing list.  To unsubscribe, please go to:
>> http://www.scottklement.com/mailman/listinfo/ftpapi
>> -----------------------------------------------------------------------
>> 
>
>-----------------------------------------------------------------------
>This is the FTPAPI mailing list.  To unsubscribe, please go to:
>http://www.scottklement.com/mailman/listinfo/ftpapi
>-----------------------------------------------------------------------
>


-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------