首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi POST验证码同步有关问题

2012-10-10 
delphi POST验证码同步问题我用idhttp 做的POST发包的软件每次都提示验证码不正确 我个人感觉是验证码不同

delphi POST验证码同步问题
我用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;

感谢

[解决办法]
直接用TIdHTTP获取校验码的图片,显示在TImage上,而不要使用Twebbrowser来获取。

热点排行