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

Re: XML POST



Hi Michael,

 From the trading partner's description, they are expecting URL-encoded 
form data to be posted.  Therefore, you should be using HTTPAPI's URL 
encoder routines to encode it (unless you prefer to do that separately?) 
and then you should upload that encoded data.

To encode it, you'll want to do something like this:

  D enc             s                   like(HTTP_URL_ENCODER)

      enc = http_url_encoder_new();
      http_url_encoder_addvar_s(enc: 'qf': 'xml');
      http_url_encoder_addvar( enc
                             :'xml'
                             : %addr(data)
                             : %len(%trimr(data)) );

Then you can send it using http_url_post or http_url_post_raw (if you 
prefer that) -- but make sure you specify the content-type!!

         http_url_encoder_getptr( enc
                                : encoded_data
                                : encoded_len);

         rc = http_url_post_raw(
                  'https://thathost.com/thatapi.aspx?qf=xml&xml='
                  : encoded_data
                  : encoded_len
                  : 1
                  : %Paddr('INCOMING')
                  : HTTP_TIMEOUT
                  : HTTP_USERAGENT
                  : 'application/x-www-form-urlencoded');


Once you've posted the data, you can/should free up the memory used by 
the URL encoded data.

        http_url_encoder_free(enc);

In the latest version of HTTPAPI, I've created shorter names for the 
"url_encoder" routines named WEBFORM.  They're just aliases (via 
"extproc") for the same routines...  but might be nicer to read and 
type.  They are WEBFORM_new, WEBFORM_setVar, WEBFORM_setPtr, 
WEBFORM_postData, and WEBFORM_close().

See EXAMPLE2 for an example of URL encoding a web form.


Michael Ryan wrote:
> Hmmm...I'm getting an error back from a trading partner for a new test
> application I'm putting together. According to their docs, the POST
> string should look like:
> 
> POST
> When using the POST method, make sure that you include the following
> Request Headers in
> your POST:
> 􀂃 http_request.setRequestHeader(ʺContent‐typeʺ,
> ʺapplication/x‐www‐form‐urlencodedʺ);
> 􀂃 http_request.setRequestHeader(ʺContent‐lengthʺ, parameters.length);
> 􀂃 http_request.setRequestHeader(ʺConnectionʺ, ʺcloseʺ);
> Be sure to substitute your actual parameter length.
> POST qf=xml&xml=xxx
> Replace xxx with the URL‐encoded XML that the API is to execute.
> 
> And here's my HTTPAPI code:
> 
>           CallP http_xproc(HTTP_POINT_ADDL_HEADER:
>                            %paddr('CONNCLOSE'));
> 
>           rc = http_url_post_raw(
>                 'https://thathost.com/thatapi.aspx?qf=xml&xml='
>                 : %Addr(Data)
>                 : %Len(%TrimR(Data))
>                 : 1
>                 : %Paddr('INCOMING'));
> 
> The Data value looks correct. I'm not sure about the "qf=xml&xml= "
> string. Do I put that in the Data variable? Do I put in in the URL?
> 
> Thanks!
> -----------------------------------------------------------------------
> 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
-----------------------------------------------------------------------