WWW server reports error after POST Request by Internet Direct components in Delphi

老子叫甜甜 提交于 2019-12-28 02:16:08

问题


I'm using Delphi XE4 and i usually use Indy with IdHttp.POST to POST request to websites,

This time, whenever i try to POST the request i get Error: Your browser is not sending the correct data.

I'm very sure that I'm POSTing the right data, and i'm using the IOHandler and CookieManager.

Been dealing with this for days(literally)

Here is the code(the site in the code):

procedure TForm1.Button1Click(Sender: TObject);
var s, lge, Kf1, Kf2, Kf3, Kf4 : String;
    lParam                     : TStringList;
begin
  S := http.Get('https://www.neobux.com/m/l/');
  Memo1.Lines.Add(S);
  getParamLge(s,lge,'lge');
  GetInput(s,Kf1,'id="Kf1"');
  GetInput(s,Kf2,'id="Kf2"');
  GetInput(s,Kf3,'id="Kf3"');
  GetInput(s,Kf4,'id="Kf4"');


  lParam := TStringList.Create;
  lParam.Add('lge='+lge);
  lParam.Add(Kf1+'=USERNAME');
  lParam.Add(Kf2+'=PASSWORD');
  lParam.Add(Kf3+'=');
  lParam.Add(Kf4+'=');
  lParam.Add('login=1');


  memo1.Lines.Add(http.Post('https://www.neobux.com/m/l/', lParam));
end;

(the getParamLge and GetInput function, are just simple copy and pos functions to extract value from the GET respone).

I thought maybe it needed cookies so i've added this in the beginning:

  Cookie.CookieCollection.Clear;
  Cookie.CookieCollection.AddClientCookies('CFID=21531887; CFTOKEN=20369251; dh=20130709111845,1920x1080,{ts ''2013-07-09 06:18:58''}; __utma=90161412.436822896.1373368451.1373368451.1373368451.1; __utmb=90161412.11.10.1373368451; __utmc=90161412; __utmz=90161412.1373368451.1.1.'+'utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __asc=06ff77ad13fc32381fd1f5d6405; __auc=06ff77ad13fc32381fd1f5d6405; __atuvc=4%7C28; MS=flat');

But all in vain.


回答1:


I'm very sure that I'm POSTing the right data

Since it does not work - obviously you do not (or Delphi does not - that makes no difference for server).

You should start usual debugging loop:

  1. Observe reference working behaviour.
  2. Observe your program behavior
  3. Spot the difference
  4. Eliminate the difference
  5. Check if the program works now
  6. If not - go to step 2.

Reference implementation would be some WWW browser working with site: Opera, Chrome, Firefox, MS IE, etc.

  • Observing tool would be some HTTP Sniffer like WireShark or OmniPacket or Microsoft Net Monitor or else, however this tinkers with OS work on rather deep level.
  • Or it can be local proxy with GUI, like Proxomitron or Membrane Monitor - but that would require special setup for both the program and the browser, to route their traffic through that local proxy.

Then you should read about HTTP, starting with shallow observation at Wikipedia and then opening related RFC documents (specifications of different part of HTTP protocol) so that you would understand what do the observed differences mean and how to fix them. For example many people use POST request when they actually should use GET request or such.

You want to debug HTTP program but for this HTTP logs, workign and borken, are required and your question lacks them. More so, most probably you can fix it your self, just bring your program's HTTP log to accordance with both RFCs theory and working browsers practice.



来源:https://stackoverflow.com/questions/17546558/www-server-reports-error-after-post-request-by-internet-direct-components-in-del

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!