不知道怎么回事,傳一個引數時正常,但串倆是會報錯400.
請各位幫忙解決一下分不夠可以再加謝謝.
傳倆引數的代碼:
procedure TFrmMain.btnLoginClick(Sender: TObject);
var
resParams: TStringStream;
postParams: TStringList;
begin
btnLogin.Enabled := False;
resParams := TStringStream.Create('');
postParams := TStringList.Create;
try
mmLog.Lines.Clear;
IdHTTP.Request.CacheControl :='no-cache';
IdHTTP.Request.Connection :='Keep-Alive';
IdHTTP.Request.Accept :='text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
IdHTTP.Request.ContentType :='application/x-www-form-urlencoded';
IdHTTP.Request.AcceptCharSet := 'UTF-8';
IdHTTP.Request.AcceptEncoding := 'UTF-8';
IdHTTP.Request.AcceptLanguage := 'UTF-8';
IdHTTP.HandleRedirects :=True; //允許重定向,因為這個站點會發生重定向
IdHTTP.AllowCookies :=True;
IdHTTP.HTTPOptions :=[hoForceEncodeParams];
postParams.Clear;
postParams.Add('account=帳號');
postParams.Add('password=密碼');//把這個注釋了傳1個引數就沒問題!!!奇怪、?
//postParams.Add('url=/console/remote/');
resParams.WriteString('');
IdHTTP.Request.Referer :='https://sunlogin.oray.com/passport/login?lang=zh_CN'; //設定來路,此網站要求
IdHTTP.Post('https://sunlogin.oray.com/passport/login?lang=zh_CN',postParams,resParams);
mmLog.Lines.Add(Utf8ToAnsi(resParams.DataString));
finally
resParams.Free;
postParams.Free;
btnLogin.Enabled := True;
end;
end;
uj5u.com熱心網友回復:
試試IdHTTP.Request.UserAgent 去掉indy,我用的百度,是禁止indy訪問的uj5u.com熱心網友回復:
不好意思,沒看清你的問題,請忽略我的回答。 幫頂了uj5u.com熱心網友回復:
請高手幫幫忙
uj5u.com熱心網友回復:
第二個以后的引數都要加&, 改下試試postParams.Add('account=帳號');
postParams.Add('&password=密碼');
uj5u.com熱心網友回復:
也看錯了, TStringList類不需要加&, 把引數補全, 下面URL那個引數恢復呢 , 缺少重要引數有的會報錯。uj5u.com熱心網友回復:
怎么樣,解決了么?同求方法!!!uj5u.com熱心網友回復:
貌似沒問題吧,我用delphi7自帶的indy測驗,就沒報錯誤轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/122336.html
標籤:網絡通信/分布式開發
上一篇:access 模糊查詢like 為何查詢不出來,請問錯在哪里?
下一篇:求一個定數讀取的代碼

