Pargat,
Every web service works differently. I can tell you how to use HTTPAPI, but I cannot tell you want is needed for a specific web service. If you know what the web service expects, and just need to know how to code that HTTPAPI, then I can help you. (But you have to tell me what it expects.)
The format you're sending is rather strange -- I don't know if it is right or wrong because I'm not familiar with this web service, but it is highly suspcious to me because it's so different from what most others do.
1) You are doing a POST request, which allows you to send a big stream of request data -- but you're not using it and instead are putting all your data in the URL. That's very suspcious.
2) Also closely related to #1, you are telling it that your request data is in application/json format, but you are not sending any request data -- so that doesn't make much sense.
3) You have both form fields (aka name/value pairs) and JSON in the same request. Most web services use one or the other, not a mixture of both.
4) It doesn't not appear that you have URL encoded your data, despite that you're putting it in the URL. Therefore, any special characters you use could cause problems.
Again -- all of this COULD be valid and expected with this web service, I have no way of knowing. But MOST web services that I've used don't work the way you've coded this.
-SK
On 5/6/17 7:38 PM, Pargat Singh wrote:
Hi Scott,
When i try to send message using procedure http_req in JSON format, I get code 400 in RC and gets nothing in response parameter. But i see "400 Bad Request" error in http log, below is how i'm invoking http_req and snippet from http log.
Do i need to use any different procedure/parm to pass data in JSON format? When I send message as named value pair then it works perfectly.
httpurl = https://xyz.com.com/
048216022518/RTI_TRAX_Q? "Location":"Action="">MessageBody={ 06031","UID":"UID12345"," Quantity":-8,"EventSource":" WMI","EventBucket":"AVAILABLE" ,"EventType":"Adjustment"," EventReasonCode":"CycleCount", "EventSeq":11,"Timestamp":" 2017-04-05-14.15.04.409000"}
rc = http_req('POST': httpurl: *omit: ResponseMessage: *omit: *omit: 'application/json') ;
SetError() #13: HTTP/1.1 400 Bad Requestrecvresp(): end with 400recvdoc parms: identity 0header_load_cookies() enteredrecvdoc(): enteredSetError() #0:recvdoc(): Receiving 0 bytes.recvdoc(): Nothing to receive, exiting...SetError() #13: HTTP/1.1 400 Bad Requesthttp_close(): entered
Thanks,Pargat
On Fri, May 5, 2017 at 7:14 AM, Pargat Singh <pargat2k3@xxxxxxxxx> wrote:
Scott,
Thanks for the details. It seems error comes only in http_req procedure. I tried same with HTTPAPI command and it didn't blow and shows actual error. If you are planning to make change in http_req then please let me know and I can test it out.
ssageBody=Loc:6603') DOWNLOAD('/home/gurayap/webresponse') REQTYPE(*POST) UPLOAD('/home/gurayap/webresponse') PROXY('www-proxy-dev.tru.com:8 080 ')DEBUG('/home/gurayap/httplog.txt')
30 SSL Handshake: (GSKit) Peer not recognized or badly formatted messagereceive
Thanks,Pargat
On Fri, May 5, 2017 at 6:02 AM, Scott Klement <sk@xxxxxxxxxxxxxxxx> wrote:
Pargat,
I do not receive an error when I run your program. However, I think I see why... it is not because of your URL that you are getting this error, it is because you are experiencing a "Peer not recognized or badly formatted message received" error during the SSL handshake. I don't receive that problem, presumably because I'm running a different version of the IBM i operating system (or maybe a different PTF level) that has improvements to the SSL software (GSKit).
It looks that when it fails during the SSL Handshake step, HTTPAPI tries to close the SSL environment twice. The first time works, but the second time the environment is set to null, and so it gets a pointer error.
I can try to fix this... but since I can't reproduce it, I have no way to test my fix.
-SK
On 5/4/2017 7:34 PM, Pargat Singh wrote:
Thanks Scott.
I changed the definition of variable in my program and reverted the change i made in HTTPAPI. After change i retried again and got same error "*Pointer not set for location referenced*". This is the program I'm testing with, it's happening when i use any invalid URL, e.g. xyz.com <http://xyz.com>.
Please let me know if you need more details.
**FREE
/copy qrpglesrc,httpapi_h
dcl-s httpurl varchar(5000) ;
dcl-s ResponseMessage varchar(1600000:4) ;
dcl-s HttpLogFileIfsPath varchar(200) ;
dcl-s rc zoned(10) ;
httpurl = 'https://xyz.com/048216022518/' + *Below is from log file.*
'RTI_TRAX_Q?Action="">e&MessageBody=' +
'Loc:6603,Type:CC,SKN:423465,UID:B1234567,' +
'Qty:1000,Seq:1,TimeStamp:2017-04-05-14 .15.04.409000' ;
HttpLogFileIfsPath = '/home/gurayap/httplog.txt' ;
http_debug(*ON: HttpLogFileIfsPath);
rc = http_req('POST'
: httpurl
: *omit
: ResponseMessage
: *omit
: *omit
: 'application/json') ;
*InLr = *On;
recvresp(): entered
HTTP/1.1 200 Connection established
SetError() #13: HTTP/1.1 200 Connection established
recvresp(): end with 200
recvdoc parms: identity 0
header_load_cookies() entered
SNI hostname set to: xyz.com <http://xyz.com>
(GSKit) Peer not recognized or badly formatted message received.
ssl_error(415): (GSKit) Peer not recognized or badly formatted message received.
SetError() #30: SSL Handshake: (GSKit) Peer not recognized or badly formatted message received.
http_close(): entered
Thanks,
Pargat
On Thu, May 4, 2017 at 5:08 PM, Scott Klement <sk@xxxxxxxxxxxxxxxx <mailto:sk@xxxxxxxxxxxxxxxx>> wrote:
Pargat,
I do not recommend changing the prototype in HTTPAPI. If you are
doing this, then you must make sure that it is changed everywhere
in HTTPAPI and is not causing problems. I cannot help you with
this, I will not support it if you make your own changes to
HTTPAPI, then you must support it yourself.
Instead, please define your variable as varying(4). (It can be
any length). This will make it compatible with http_req() and you
won't need to change the prototype.
I am not familiar with the pointer error you've cited -- please
make sure it is not due to an incorrect change you've made to
HTTPAPI. If it is not, then please tell me how I should call
HTTPAPI to reproduce this problem.
-SK
On 5/4/2017 1:33 PM, Pargat Singh wrote:
Thanks Scott. This is really very helpful information.
I installed the latest HTTPAPI version and tested using
http_req procedure and it works like a charm. As of now, these
are the 2 challenges I faced while testing:
1. My program which invokes http_url is fully free and was not
compiling due to error "*The type and attributes of the
parameter do not match those of the prototype*" when i defined
the response parm as (dcl-s ResponseMessage varchar(1600000) ;). In prototype it's defined as below.
*D ResultStr a len(16000000) varying options(*varsize:*omit:*nopass) *
I changed the prototype to below and then it got compiled.
Please advise if i shouldn't be changing prototype definition.
*D ResultStr 1600000a varying
options(*varsize:*omit:*nopass)*
2. For testing, when i changed my URL to make it invalid just
to determine if i get valid error message. I got an error
"*Pointer not set for location referenced*" in module
*COMMTCPR4*, procedure *CommTcp_Hangup*. Error is coming on
*close(fd)* statement.
D CommTcp_Hangup...
D PI 1N
D peHandle * value
c eval p_CommTcp = peHandle
*c if close(fd) = 0 *
c return *ON
c else
c return *OFF
c endif
P E
call PGM(TESTWEB2)
(GSKit) Peer not recognized or badly formatted message received.
Pointer not set for location referenced.
The call to HTTP_REQ ended in error (C G D F).
Thanks,
Pargat
On Thu, May 4, 2017 at 12:15 AM, Scott Klement
<sk@xxxxxxxxxxxxxxxx <mailto:sk@xxxxxxxxxxxxxxxx>
<http://sqs.us-east-1.amazonaw<mailto:sk@xxxxxxxxxxxxxxxx <mailto:sk@xxxxxxxxxxxxxxxx>>> wrote:
Pargat,
There are older routines and newer routines in HTTPAPI. I
would
recommend using the newer ones if you can, they have a
much more
streamlined and simple interface. Use the older routines
if you
need compatibility with older OS versions, including
versions of
RPG before it supported larger strings.
Under the covers, all of the ways of doing POST use the
same HTTP
POST request. The difference is how they interface to
your program.
The old methods for POST are:
-- http_url_post(): Data to upload comes from a pointer, data
received goes to a file in the IFS
-- http_url_post_raw(): Data to upload comes from a pointer,
received data goes to a callback routine.
-- http_url_post_stmf(): Data to upload comes from an IFS
file,
received data goes to a file.
-- http_url_post_raw2(): Callback is used for both the
data to
upload, and the received data
-- http_url_post_xml(): Data to upload comes from a
pointer. Data
received is parsed by an XML parser, and parsed data is
passed to
two callbacks.
The new methods are:
-- http_req(): Works with any operation, including POST.
Data to
upload can come from a file or a string. Data received
also can
be a file or string.
-- http_string(): streamlined version of http_req(). Input and
output are both strings. Errors are sent as *escape messages
instead of return codes.
-- http_stmf(): streamlined version o http_req() where
input/output are both files. Errors are sent as *escape
messages.
Please do not call HTTPCMDR4 directly, that is only meant
for use
from the HTTPAPI command object, and I cannot provide
support for
calling this program directly.
Given that you don't want special behavior for errors,
http_req()
might be easiest.
url = "" href="http://your-url-here" rel="noreferrer" target="_blank">http://your-url-here';
rc = http_req('POST': url: *omit: OutputString: *omit:
InputString: 'application/json');
the rc will tell you what you got back from the server.
-1 = error occurred, communications didn't succeed
0 = time out
1 = success (same as 200 HTTP code)
numbers higher than 1 are HTTP response codes that were
sent from
the server, such as 404 (not found), 403 (forbidden), 500
(server
detected error), etc. If you get a number higher than 0
in the
rc, you will also have data in the OutputString (if the server
sent any.)
Good luck!
On 5/3/17 10:35 AM, Pargat Singh wrote:
Hi,
I'm very new to HTTPAPI so need a little help here,
sorry might
be asking basic/stupid questions.
I need to post data as named value pair and data is
embedded in
URL itself, example below. I was planning to use
HTTPAPI command
but I believe that won't return me error message back
in program.
So other option is to call HTTPCMDR4 program with
required parms
and it will return me error code and message back in
my calling
program.
Not sure if i should be calling this program or use
any other
procedure e.g. http_url_post_raw2. But with this not
sure how to
trap the error message if connection/POST is not
successful.
https://xyz.com/048216022518/RTI_TRAX_Q?Action="">
<https://xyz.com/048216022518/RTI_TRAX_Q?Action=""> >
<https://xyz.com/048216022518/RTI_TRAX_Q?Action="">&
<https://xyz.com/048216022518/RTI_TRAX_Q?Action=""> >>*MessageBody=Loc:6030,Type=F RZ,SKN:423465768675,Qty:1000*
*
*
In addition, i need to send data in JSON format so i
used Scott's
YAJL utility and tried to generate data as it's shown
in Scott's
example. But when i check the http log it shows junk
characters,
below is snippet from http log file. In debug, it
shows junk too
but i believe that might be due to EBCDIC vs 1208. In
debug i
pulled HEX equivalent of data which was showing in program
variable and then converted to ASCII format. It showed
correctly
but not sure why it's transmitting as junk. Below
message was
posted on remote system with just "-" and rest of the
data was
ignored/not transmitted. Please help.
do_oper(POST): entered
There are 0 cookies in the cache
POST
/048216022518/RTI_TRAX_Q?Action=SendMessage&MessageBody=-#
<?Ä/ÈÑ?> ë?ÍÊÄÁ ï(ë éÍ/>ÈÑÈ` '
Host: sqs.us-east-1.amazonaws.com
<http://sqs.us-east-1.amazonaws.com >
s.com
<http://sqs.us-east-1.amazonaws.com >>
User-Agent: http-api/1.32
Thanks,
Pargat
--
_______________________________________________ <mailto:Ftpapi@lists.scottklem
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
<mailto:Ftpapi@lists.scottklement.com >
ent.com
<mailto:Ftpapi@lists.scottklement.com >>
http://scottklement.com/mailman/listinfo/ftpapi
<http://scottklement.com/mailman/listinfo/ftpapi >
<http://scottklement.com/mailman/listinfo/ftpapi
<http://scottklement.com/mailman/listinfo/ftpapi >>
-- _______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx <mailto:Ftpapi@lists.scottklement.com >
http://scottklement.com/mailman/listinfo/ftpapi
<http://scottklement.com/mailman/listinfo/ftpapi >
--
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi
--
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi
-- _______________________________________________ Ftpapi mailing list Ftpapi@xxxxxxxxxxxxxxxxxxxxxx http://scottklement.com/mailman/listinfo/ftpapi