Pulover, I use the GET/POST very often, I wish to help you, I will consider write a tutorial, and please feel free to contact me via PM or gmail.
Some points to do the http request:
1. cookie
The most important thing. This is how the browser know you are loged in or not.
I suggest to clear the cookie before start recording in Fiddler. And when finished recording, check out which http request has cookie changes, generally those requests are needed. For example:
POST
https://secure.xxx.com/secure_login.html HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Referer:
https://secure.xxx.com/secure_login.html
Accept-Language: pt-BR
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: secure.xxx.com
Content-Length: 133
Connection: Keep-Alive
Cache-Control: no-cache
Cookie:
S=eho838c56c7eednra0lum2fmo3; B=b=939124E86791B563; __utma=50703532.935389667.1380635149.1380733872.1380740551.5; __utmz=50703532.1380635149.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); lithiumSSO%3A=~2oe1bduIWA5PsaJoU~N8WHENIFWKwufCJJW52aSPFrQ9qtzM6ZX0OAYm_AuzdC9uA0rn_Pd8CVWpRqhhR8EBQNQlawbSeepG6sZN1Umo9Lp_vRwDc34NuDiEtT8K02NzIMGDDapwG8Fd4ZLvPCZ8bCvlwnpNalvSllGbgLFgz7cIBWy6moAGlKO2d548zaFtshlo44lNGwOcJhgiXfpeboGipLfNOAJaDZcVgU6wvy8UtJVhMq-fKzyVo13xDIULFkq0tbG25n0bWhGMSOxf_miRI1VS0BiOrGCJkvYBAXbcV_2ANoO8pTTcwbx_4.; __utmb=50703532.0.10.1380740551; __utmc=50703532; remember=N
username=
[email protected]&token=2fd7d1a7242bfcb48d443d5b6eccfcf8&password=pass&tprefs1=&tprefs2=2a2hWfc2qiMc.1ij0_p.5BgYi1
The cookie
"S=eho838c56c7eednra0lum2fmo3; B=b=939124E86791B563;" is probably needed, so it's best to get this cookie before post. Usually this cookie will be set when opening the login page.
The cookie marked as yellow text, like
"__utma=" is no use for us, I've searched this on google before, people said this is for google recording.
2. Referer and other headers
Referer is also suggest to send in the http request. Sometimes the request will fail when there's no referer.
User-Agent suggest to use too.
Other headers is not very important, but when the request is failed, try to adding more header will help.
---------------------------------------------------------
btw: I use
HttpWatch and
HTTP Analyzer V7 for recording http request.
HTTP Analyzer V7 can record all process or a specific process. And I use HTTPRequest.ahk to do the GET/POST.
=============================================================
HTTPRequest.ahk Example for this forum login:
Code: Select all
#Include <HTTPRequest>
#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
ListLines Off
; Set HTTPRequest Options
Options := "+Flag: INTERNET_FLAG_NO_COOKIES" ; Not use the IE browser's cookie
Options .= A_IsUnicode ? "`nCharset: UTF-8" : ""
Tooltip, Get cookie and sid...
cookie := ""
url := "http://www.auto-hotkey.com/boards/ucp.php?mode=login"
HTTPRequest(url, InOutData := "", InOutHeader := Headers(), Options)
cookie := CookiesFromHeader(InOutHeader)
; sid := RegExReplace(InOutHeader, "^.*phpbb3_ghjir_sid=([^;]+).*$", "$1")
sid := StrX(InOutHeader, "phpbb3_ghjir_sid=","",17, ";",1,1, "")
Tooltip, Login...
url := "http://www.auto-hotkey.com/boards/ucp.php?mode=login&sid=" sid
referer := "http://www.auto-hotkey.com/boards/ucp.php?mode=login"
data =
(LTrim Join&
username=USERNAME_HERE
password=PASSWORD_HERE
autologin=on
redirect=./ucp.php?mode=login&sid=%sid%
sid=%sid%
redirect=index.php
login=Login
)
HTTPRequest(url, InOutData := data, InOutHeader := Headers(referer), Options)
cookie .= CookiesFromHeader(InOutHeader)
if InStr(InOutData, "> Logout [")
MsgBox, Login Successful!
else
MsgBox, Login Fail.
; =========================== Functions ===========================
Headers(referer = "")
{
global cookie
Headers =
( LTRIM
Referer: %referer%
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
Cookie: %cookie%
)
return Headers
}
CookiesFromHeader( headerData ) {
while ( p := RegExMatch( headerData, "sim`a)^Set-Cookie:\s*(?P<Crumb>[^;]+);", Cookie, ( p ? p+StrLen(Cookie) : 1 ) ) )
Cookies .= ( StrLen( Cookies ) ? " " : "" ) CookieCrumb ";"
return Cookies " "
}
StrX( H, BS="",BO=0,BT=1, ES="",EO=0,ET=1, ByRef N="" ) { ; | by Skan | 19-Nov-2009
Return SubStr(H,P:=(((Z:=StrLen(ES))+(X:=StrLen(H))+StrLen(BS)-Z-X)?((T:=InStr(H,BS,0,((BO
<0)?(1):(BO))))?(T+BT):(X+1)):(1)),(N:=P+((Z)?((T:=InStr(H,ES,0,((EO)?(P+1):(0))))?(T-P+Z
+(0-ET)):(X+P)):(X)))-P) ; v1.0-196c 21-Nov-2009 www.autohotkey.com/forum/topic51354.html
}