[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: https with userid and password
Sender: Scott Klement <sk@xxxxxxxxxxxxxxxx>
Since you might make many requests and encode each one, to use HTTPAPI's
encoding routines, you must first "create an encoder". This creates
temporary space in memory that HTTPAPI will use to store info while it's
encoding data.
D Enc s like(HTTP_URL_ENCODER)
.
.
Enc = http_url_encoder_new();
Once you've created the encoder, you can add variables to it with their
values. It'll encode them properly so that the server won't choke on
them. It'll store the result in that temporary space in memory that I
mentioned above.
http_url_encoder_addvar(enc: 'xml': p_data: dataLen);
Once you've added all of the variables that you need to the encoder (in
this situation, there's just one... the xml variable) you can use the
contents of the encoder to construct a URL.
url = 'https://apps2.tradegate2000.com/import/whatever' +
+ '?' + http_url_encoder_getstr(Enc);
This'll result in a URL like 'https://. . ./whatever?xml=datadatadata'
Then you pass that URL to the http_url_post() or http_url_get() routines.
Here's a more complete example:
H DFTACTGRP(*NO) BNDDIR('LIBHTTP/HTTPAPI')
/copy libhttp/qrpglesrc,httpapi_h
D rc s 10I 0
D Enc s like(HTTP_URL_ENCODER)
D xml s 5000A varying
D url s 32767A varying
/free
xml = '<?xml version="1.0">'
+ '<testXml>'
+ ' <Dummy>Scott Klement</Dummy>'
+ ' <OtherXml>BlahBlah</OtherXml>'
+ '</testXml>';
Enc = http_url_encoder_new();
http_url_encoder_addvar(Enc: 'xml': %addr(xml)+2: %len(Xml));
url = 'https://apps2.tradegate2000.com/import' +
http_url_encoder_getstr(Enc);
rc = http_url_get(url . . .
- or -
rc = http_url_post(url . . .
http_url_encoder_free(enc);
if rc <> 1;
errmsg = http_error();
// show errmsg to user!
endif;
*inlr = *on;
/end-free
Due the fact that HTTPAPI didn't have much internal space for strings to
send to the server in version 1.12 and earlier, I recommend that you use
version 1.13 for this sort of logic. However, even so, you're limited to
around 32k (actually, it's a bit less because of the space that the other
HTTP headers use).
For anything longer than that, you really don't want to use data in the
URL. You want to use actual POST data for a document longer than that...
indeed many web browsers and web servers will choke on URL data that's
longer than 8k. (POST data has no practical limit on how large it can
be.)
I have no clue why you'd want to use variables like this on a POST
request, other than that the developer who wrote the web service didn't
really understand what he was doing. Sending the data as the body of the
POST request is a much more robust solution!!
---
Scott Klement http://www.scottklement.com
On Fri, 30 Dec 2005, Stoicescu, Adriana wrote:
In fact 'xml' is the only parameter of their program and they are asking me
to pass it with a GET syntax although it is a POST. They want the variable
to be named xml. How can I do this?
This I cannot understand.
Adriana
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------