delphi对不起,您提交的表单来源错误,请重新登录
源代码是这样,不知道哪里没有考虑到,网站一直提示 对不起,您提交的表单来源错误,请重新登录!,高手能不能帮忙分析一下?,一个表单提交
tempstr:=httpGet(url);
sCookie:='';
for i:=0 to IdHTTP1.Response.RawHeaders.Count-1 do
begin
if UpperCase(Copy(IdHTTP1.Response.RawHeaders[i],1,10))='SET-COOKIE' then
begin
sCookieTmp:=Trim(Copy(IdHTTP1.Response.RawHeaders[i],12,MAXINT));
sCookieTmp:=Copy(sCookieTmp,1,Pos(';',sCookieTmp)-1);
sCookie:=sCookie+sCookieTmp+'; ';
end;
end;
tempstr := Utf8ToAnsi(tempstr);
RegExpr:=TRegExpr.Create;
RegExpr.Expression:='name="key" value="([^<]*)">';
RegExpr.InputString:=tempstr;
if RegExpr.Exec then
begin
tempstr:=RegExpr.Match[1];
Params := TStringList.Create;
Params.Add('name=myuser');
Params.Add('psw=mypassowrd');
Params.Add('key='+tempstr);
Params.Add('sid=1');
Params.Add('backurl=http://www.ename.net/');
Params.Add('domainname=www.ename.com');
url := 'https://my.ename.cn/cas/./login/prelogin'; //active
//IdHTTP1.Request.CustomHeaders.Add('Cookie:'+sCookie);
idhttp1.Request.CustomHeaders.Values['Cookie']:=sCookie;
tempstr:=IdHTTP1.Post(url,Params);
//返回 对不起,您提交的表单来源错误,请重新登录!
//tempstr:=httpPost(url,Params);
tempstr := Utf8ToAnsi(tempstr);
Memo1.Text:=tempstr;
end else
begin
memo1.Text:='test';
end;
1. https页面,要用SSL方式登录
2. 数据头,重设为与登录时载包一样,内容如下
Accept: application/json, text/javascript, */*; q=0.01
Content-Type: application/x-www-form-urlencoded
X-Requested-With: XMLHttpRequest
Referer:
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: my.ename.cn
Content-Length: 113
Connection: Keep-Alive
Cache-Control: no-cache
Content-Length. 不用指定,默认Idhttp自动计算
提交后,取出以上列表值,看是否与登录时一样,不一样的就要重设
Indy自身Accept-Encoding: gzip, deflate 这个值,要改下源码,,不然会多一个 Identify
3.Cookie: PHPSESSID=9o59bf56c4ip94pllk4d67f9t7 这个Cookie不用自已去设.. 直接Idhttp.AllowCookie:= true; 让IDHttp去自动管理.. 如Idhttp.果想自定义的话,要先指定 Idhttp.AllowCookie:= false; 不然,自定义Cookie无效,
另外: Cookie较长时,要改下源码中分段长度, 默认长度72超过72 自定义Cookie值会换行. 若换行,会影响服务器判断
4: name=demo.abc%40qq.com&psw=123456&key=7ije32&sid=1&domainname=www.ename.net&backurl=http%3A%2F%2Fwww.ename.net%2F
Post信息要进行 httpencode
5: Content-Encoding: gzip
服务器返回信息进行了 Gzip压缩.. 你懂的..
这些都做到了,那么恭喜你,可以正常登录了 有没有复制与你使用Indy相对应版本的两个SSL的 DLL文件,到你程序所在目录,或者系统目录