[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: HTTPAPI 1.9 pre3
Hi again Tom,
>
> One possible workaround is to use Connection: close. Let me see if I can
> find some example code for doing that, and I'll write another message.
>
Attached is your POSTALK.RPG file with "Connection: close" specified.
This works great on my system, but then it worked great without it, too :)
With "connection: close" specified, the server will disconnect from us
when it's done sending data. That means that HTTPAPI won't get stuck
waiting on a timeout because the socket will be closed, it'll return right
away.
It might solve your problem (but then, it might not? who knows) Please
try the attached source, and let me know
Thanks
H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('LIBHTTP/HTTPAPI')
D/copy libhttp/qrpglesrc,httpapi_h
D XMLDOC DS
D Header 1 38
D CZIP 39 43
D CSTA 44 45
D cmd pr extpgm('QCMDEXC')
D command 200A const
D length 15P 5 const
D CRLF C CONST(x'0D25')
D rc s 10I 0
D msg s 52A
D data s 1024A
D INCOMING PR 10I 0
D 10I 0 value
D 8192A options(*varsize)
D 10I 0 value
D Retdata S 3276A
D Retlen S 10I 0 Inz(1)
D nextpos S 10I 0 inz(1)
D lenstr S 10I 0 inz(1)
*procedure prototypes
D GETXML PR
D translate PR ExtPgm('QDCXLATE')
D length 5P 0 const
D data 32766A options(*varsize)
D table 10A const
D ConnClose PR
D addl_hdr 1024A varying
D pos S 5U 0
D begpos S 5U 0
D endpos S 5U 0
D xmldata S 52A
*
*---------------------------------------------------------------------
* Set up parameters to Post to FleetSuite server
*---------------------------------------------------------------------
c eval data='User=tom' +
c '&PassWord=fishing' +
c '&City=' +
c '&State=' +
c '&Zip=08540' +
c '&Address=' +
c '&DestCity=Warminster' +
c '&DestState=PA' +
c '&DestZip=18974' +
c '&DestAddress=' +
c '&RouteType=' +
c '&RouteClass=' +
c '&TollAvoid='+
c '&BordersOpen='+
c '&CondenseLevel='
* '&CondenseLevel=1' + CRLF
*
c callp http_xproc(HTTP_POINT_ADDL_HEADER:
c %paddr('CONNCLOSE'))
C eval rc = http_url_post_raw(
C 'http://transport.alk.com/' +
C 'Fleetsuite.asmx/GetDirFromAdrToAdr?'
C : %addr(data): %len(%trimr(data))
C : 1
C : %paddr('INCOMING')
C : HTTP_TIMEOUT
C : HTTP_USERAGENT
C : 'application/x-www-form-urlencoded')
*
C if rc <> 1
C eval msg = http_error
C dsply msg
c endif
C if retlen > 1
*---------------------------------------------------------------------
* Convert ASCII data returned to EBCIDEC
*---------------------------------------------------------------------
C callp Translate(retlen: retdata: 'QTCPEBC')
C callp GETXML
C endif
C eval *inlr = *on
*---------------------------------------------------------------------
* Incoming - receives the raw data returned in the web
* This procedure is called from within the 'black box' of
* api http_url_post_raw. Note 5th parm
*--------------------------------------------------------
P incoming B
D incoming PI 10I 0
D descriptor 10I 0 value
D data 8192A options(*varsize)
D datalen 10I 0 value
* Make sure we don't overflow the string:
c eval retlen = (nextpos + datalen)
c if retlen > %size(retdata)
c eval datalen=datalen-(%size(retdata)-retlen)
c endif
* If there is nothing to write, return THAT...
c if datalen < 1
c return 0
c endif
* Here we add any data sent to the end of our 'retdata' s
c eval %subst(retdata: nextpos) =
c %subst(data:1:datalen)
c eval nextpos = nextpos + datalen
c return datalen
P incoming E
*---------------------------------------------------------------------
* GETXML parses returned XML from ALK FleetSuite
*
*--------------------------------------------------------
P GETXML B EXPORT
D GETXML PI
* Get the Result
C EVAL endpos =1
C EVAL pos = 1
C EVAL pos = %scan('<Result>' : retdata:endpos)
C if pos > 1
C EVAL endpos = %scan('</Result>':retdata:pos+8)
C eval lenstr = (endpos -(pos +8))
C eval %subst(xmldata: 1) =
C %subst(retdata:(pos+8):lenstr)
C dsply xmldata
C else
C 'No Result' dsply
C ENDIF
* Get the Reason
C EVAL pos = 1
C EVAL pos = %scan('<Reason>' : retdata:endpos)
C if pos > 1
C EVAL endpos = %scan('</Reason>':retdata:pos+8)
c eval lenstr = (endpos -(pos +8))
c eval %subst(xmldata: 1) =
c %subst(retdata:(pos+8):lenstr)
c dsply xmldata
C else
C 'Reason=None' dsply
C ENDIF
*
* Get the direction strings
C EVAL endpos =1
C EVAL pos = 1
C DOU pos = 0
C EVAL pos = %scan('<string>' : retdata:endpos)
C if pos > 1
C EVAL endpos = %scan('</string>':retdata:pos+8)
C eval lenstr = (endpos -(pos +8))
C eval %subst(xmldata: 1) =
C %subst(retdata:(pos+8):lenstr)
C dsply xmldata
C ENDIF
C end
P GETXML E
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* ConnClose(): Specify the "Connection: close" additional header
* to HTTPAPI. This tells the HTTP server to disconnect
* when done sending data.
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P ConnClose B
D ConnClose PI
D addl_hdr 1024A varying
c eval addl_hdr = 'Connection: close' + x'0d25'
P E