delphi POST验证码同步问题

jnxdf0102 2012-09-24 09:02:20
我用idhttp 做的POST发包的软件

每次都提示验证码不正确 我个人感觉是验证码不同步。意思软件应该提交的验证码是新的验证码 而软件上面显示的是旧的验证码

下面是我的代码 希望大家指正 修改的地方
////////////////////////////////////////
function CanGetIECookie(const URL:string; var Cookie:string):boolean;
var lpvBuffer:array[0..1000] of byte;
lpdwBufferLength:cardinal;
begin
lpdwBufferLength:=sizeof(lpvBuffer);
result:=InternetGetCookie(PChar(URL),nil,@lpvBuffer,lpdwBufferLength);
if result then
Cookie:=pchar(@lpvBuffer);
end;

procedure TForm1.Button1Click(Sender: TObject);
var strMsg:string;
sParams: TStringStream;
s,str,CookieStr:string;
snc:string;
begin
memo1.clear;
s := 'http://px.zznews.gov.cn/xxxdzc.php?group=28';
if CanGetIECookie(s, str) then
begin
CookieStr := 'Cookie: ' + str;
idHttp1.Request.CustomHeaders.Text := CookieStr;
end else
begin
ShowMessage('没有发现本地Cookie,请从Web页面登陆一次。');
Exit;
end;
sParams := TStringStream.create('');
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
idhttp1.Request.Referer:='http://px.zznews.gov.cn/xxxdzc.php?group=28C:\Program Files\Microsoft\soft1\Internet Explorar';
try
sParams.WriteString('nt=12996417340&user=&vid=|BC9C33DQkLDAAMAA8ADQBdDg5bDgkBCAwKCgwOCQ0ACloO&randcode='+trim(edit1.Text)+'&time=1348487906531&_=') ;
/// idhttp1.request.customheaders.text:='cookie:'+'dbsessionId=c89aa4d090825f47998eb6bd1fdeb8dc; cnzz_a2523094=0; sin2523094=; rtime=0; ltime=1323581940578; cnzz_eid=14226567-1323577009-';
strMsg:=IdHTTP1.post('http://px.zznews.gov.cn/ajax.php',sParams) ;
memo1.Text:=UTF8ToAnsi(strmsg);
finally
sParams.Free ;
end;
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
memo1.Clear;
edit1.Clear;
webbrowser1.Navigate('http://px.zznews.gov.cn/includes/rand_func.php?rc=42107');
edit1.SetFocus;
end;

感谢
...全文
175 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jnxdf0102 2012-09-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

直接用TIdHTTP获取校验码的图片,显示在TImage上,而不要使用Twebbrowser来获取。
[/Quote] 感谢 这个问题 的确是关键 我试一下~~
广州佬 2012-09-24
  • 打赏
  • 举报
回复
直接用TIdHTTP获取校验码的图片,显示在TImage上,而不要使用Twebbrowser来获取。

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧