Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...