[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: HttpApi Urgent Help **
Mike
Thanks a lot for your advise.
I used Fiddles and I did a step forward
In fact I noticed that navigating to the initial page
[1]http://www.website.net/prereg/program.do?e=110&t=10&c=aBcDeFgHi
the server set some cookies and then redirect to an other page
[2]http://www.website.net/prereg/EspFormSend.do
Here follow is what Fiddles says browsing to the site:
1) **Header Request**
GET /prereg/[3]program.do?e=110&t=10&c=aBcDeFgHi HTTP/1.1
Host: www.website.net
User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-IT,it,en-US,en;q=0.9,fr-fr;q=0.9,fr;q=0.9,en-CA;q=0.9,de-DE;
q=0.9,de;q=0.9,pt-BR;q=0.8,pt;q=0.8,en-gb;q=0.8,nb-NO;q=0.8,nb;q=0.8,af-ZA;q=0.7
,af;q=0.7,se-SE;q=0.7,se;q=0.7,en-AU;q=0.7,ro-RO;q=0.6,ro;q=0.6,nl-NL;q=0.6,nl;q
=0.6,is-IS;q=0.6,is;q=0.6,de-CH;q=0.5,de-AT;q=0.5,es-ES;q=0.5,es;q=0.5,en-IE;q=0
.5,da-DK;q=0.4,da;q=0.4,kl-GL;q=0.4,kl;q=0.4,es-CR;q=0.4,eu-ES;q=0.4,eu;q=0.3,ru
-RU;q=0.3,ru;q=0.3,zh-CN;q=0.3,zh;q=0.3,en-en;q=0.2,hu-HU;q=0.2,hu;q=0.2,it-it;q
=0.2,pt-PT;q=0.2,en-GB;q=0.1,sv-SE;q=0.1,sv;q=0.1,se-se;q=0.1,It-IT;q=0.1,it;q=0
.1,en-us;q=0.0,en;q=0.0
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
2) **Reply**
HTTP/1.1 302 Found
Date: Wed, 04 Jan 2012 11:31:13 GMT
Server: IBM_HTTP_Server
Pragma: No-cache
Cache-Control: no-cache,no-store,max-age=0
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Location: http://www.website.net/prereg/EspFormSend.do
Content-Length: 0
Set-Cookie: JSESSIONID=0000AAt8c9U-xAA-AAqAAAlAAAp:12ir419l9; Path=/prereg; Doma
in=.website.net
Set-Cookie: JSESSIONID=0000Bf3BBB_0kjooBukBBlBBh2r:12ir419l9; Path=/prereg; Doma
in=.website.net
Keep-Alive: timeout=10, max=100
Connection: Keep-Alive
Content-Type: text/html
Content-Language: en-US
3) **Header Request from Redirect**
GET http://www.website.net/prereg/EspFormSend.do HTTP/1.1
Host: www.website.net
User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-IT,it,en-US,en;q=0.9,fr-fr;q=0.9,fr;q=0.9,en-CA;q=0.9,de-DE;
q=0.9,de;q=0.9,pt-BR;q=0.8,pt;q=0.8,en-gb;q=0.8,nb-NO;q=0.8,nb;q=0.8,af-ZA;q=0.7
,af;q=0.7,se-SE;q=0.7,se;q=0.7,en-AU;q=0.7,ro-RO;q=0.6,ro;q=0.6,nl-NL;q=0.6,nl;q
=0.6,is-IS;q=0.6,is;q=0.6,de-CH;q=0.5,de-AT;q=0.5,es-ES;q=0.5,es;q=0.5,en-IE;q=0
.5,da-DK;q=0.4,da;q=0.4,kl-GL;q=0.4,kl;q=0.4,es-CR;q=0.4,eu-ES;q=0.4,eu;q=0.3,ru
-RU;q=0.3,ru;q=0.3,zh-CN;q=0.3,zh;q=0.3,en-en;q=0.2,hu-HU;q=0.2,hu;q=0.2,it-it;q
=0.2,pt-PT;q=0.2,en-GB;q=0.1,sv-SE;q=0.1,sv;q=0.1,se-se;q=0.1,It-IT;q=0.1,it;q=0
.1,en-us;q=0.0,en;q=0.0
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Cookie: JSESSIONID=0000Bf3BBB_0kjooBukBBlBBh2r:12ir419l9
4) **Reply after Redirect**
HTTP/1.1 200 OK
Date: Wed, 04 Jan 2012 11:31:13 GMT
Server: IBM_HTTP_Server
Pragma: no-store,no-cache
Cache-Control: no-cache, no-store,must-revalidate, max-age=-1
Expires: -1
Keep-Alive: timeout=10, max=99
Connection: Keep-Alive
Content-Type: text/html;charset=ISO-8859-1
Content-Language: en-US
Content-Length: 13206
.......................... and the HTML codes of the Page
I have modified my rpg to include the cookies handling (from httpapi example) bu
t without success.
HereFollow My RPG:
*****************************************************************
* Pgm to issue free tickets for Trade Exhibition *
*****************************************************************
* ---------------------------------
* H Spec
* ---------------------------------
H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('HTTPAPI')
* ---------------------------------
* Files
* ---------------------------------
* ---------------------------------
* Prot
* ---------------------------------
/define WEBFORMS
D/copy LIBHTTP/qrpglesrc,httpapi_h
*
D cmd pr extpgm('QCMDEXC')
D command 200A const
D length 15P 5 const
*
D read_hdr PR
D hdr 32767A varying const
*
D addl_hdr PR
D addl_data 1024A varying
* ---------------------------------
* Variables
* ---------------------------------
D upper C 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
D lower C 'abcdefghijklmnopqrstuvwxyz'
D rc s 10I 0
D msg s 52A
D wkNewLoc s 1024A varying
D wkCookie s 1024A varying
*
D Form s like(WEBFORM)
*
D myPointer s *
D dataSize s 10I 0
*
D url1 c const('http://www.webpage.net/prere+
D g/program.do')
D getData c const('[4]?e=110&t=10&c=aBcDeFgHi')
D url2 c const('http://www.webpage.net/prere+
D g/EspSendSingleEmail.do')
D UserAgent c const('Mozilla/5.0 (compatible; MSIE+
D 9.0; Windows NT 6.0; Trident/5.0)')
D eMail c const('email@xxxxxxxxx')
D nTickets c const('1')
D Name c const('Alex')
D MsgEng c const('English Message')
D MsgIta c const('Italian Message')
**************************************************************************
** Start - Access to the Webpage making the identification
**************************************************************************
* delete old working file - just for debug purpose
c callp(e) cmd('rmvlnk ''/tmp/test1.html''': 200)
c callp(e) cmd('rmvlnk ''/tmp/test2.html''': 200)
c callp(e) cmd('rmvlnk ''/tmp/test3.html''': 200)
* set cookies space
c callp http_xproc(HTTP_POINT_PARSE_HDR_LONG:
c %paddr('READ_HDR'))
c callp http_xproc(HTTP_POINT_ADDL_HEADER:
c %paddr('ADDL_HDR'))
*
c eval wkNewLoc = url1+GetData
*
c dou rc <> 302 and rc <> 301
c eval rc = http_url_get(wkNewLoc:
c '/tmp/test1.html:30:UserAgent')
c enddo
* for debug purpose... display webpage retrived
c callp cmd('DSPF ''/tmp/test1.html''': 200)
* check for any error
c if rc <> 1
c eval msg = http_error
c dsply msg
c return
c endif
*
* now we should be authenticated and thus go ahead with the form
** Open the Webform and set variables
C eval Form = WEBFORM_open
c callp WEBFORM_SetVar(Form: 'exsmsgit':MsgIta)
c callp WEBFORM_SetVar(Form: 'exsmsgen':MsgEng)
c callp WEBFORM_SetVar(Form: 'email': eMail)
c callp WEBFORM_SetVar(Form: 'num': nTickets)
c callp WEBFORM_SetVar(Form: 'nomedest': Name)
** Send Post Data to the Pointer
c callp WEBFORM_postData( Form : myPointer
c : dataSize )
** Call the url sending data from the pointer
c eval rc = http_url_post(
c url2
c : myPointer
c : dataSize
c : '/tmp/test2.html'
c : HTTP_TIMEOUT
c : HTTP_USERAGENT
c : 'application/x-www-form-urlencoded' )
c if rc = 302
c eval rc = http_url_get( http_redir_loc
c : '/tmp/test3.html')
c endif
c if rc <> 1
c eval msg = http_error
c dsply msg
c else
c callp cmd('DSPF ''/tmp/test2.html''': 200)
c endif
** free memory
c callp WEBFORM_close(Form)
c eval *inlr = *on
c return
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* this is called by HTTPAPI when we receive responses from the
* HTTP servers. We are interested in the contents of the
* "set-cookie" and "location" keywords from the HTTP headers
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P read_hdr B
D read_hdr PI
D hdr 32767A varying const
D wwHdr s 32767A varying
D wwPos s 10I 0
D wwLen s 10I 0
D LF s 1A inz(x'25')
D CRLF s 2A inz(x'0d25')
c eval wwHdr = hdr
c lower:upper xlate wwHdr wwHdr
***
*** see if we received a "location" header:
***
c eval wwPos = %scan(LF+'LOCATION:': wwHdr)
c if wwPos > 0
c eval wwPos = wwPos + %len(LF+'LOCATION:') + 1
c eval wwLen = %scan(CRLF: wwHdr: wwPos) - wwPos
c if wwLen > 0
c eval wkNewLoc = %subst(hdr:wwPos:wwLen)
c endif
c endif
***
*** see we received a "set-cookie" header:
***
c eval wwPos = %scan(LF+'SET-COOKIE:': wwHdr)
c if wwPos > 0
c eval wwPos = wwPos + %len(LF+'SET-COOKIE:' ) + 1
c eval wwLen = %scan(CRLF: wwHdr: wwPos) - wwPos
c if wwLen > 0
c eval wkCookie = %subst(hdr:wwPos:wwLen)
c endif
c endif
c return
P E
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* If wkCookie is set, we'll send it as an additional header on
* our next request to the HTTP server...
*
* Note: Cookie handling should probably be a lot more sophisticated
* than this. Please take this as a very simplified example.
* (normally, we'd do extra things like parsing the cookie,
* making sure the domain matches, and saving it for future
* sessions until it reaches it's expiration)
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P addl_hdr B
D addl_hdr PI
D addl_data 1024A varying
c if %len(wkCookie) > 0
c eval addl_data = 'cookie: '+ wkCookie + x'0d25'
c else
c eval addl_data = ''
c endif
P E
References
1. http://www.website.net/prereg/program.do?e=110&t=10&c=aBcDeFgHi
2. http://www.website.net/prereg/EspFormSend.do
3. http://www.website.net/prereg/program.do?e=110&t=10&c=aBcDeFgHi
4. http://www.website.net/prereg/program.do?e=110&t=10&c=aBcDeFgHi
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------