WWW服务器报告错误后POST请求由Delphi中的Direct Direct组件 [英] WWW server reports error after POST Request by Internet Direct components in Delphi

查看:162
本文介绍了WWW服务器报告错误后POST请求由Delphi中的Direct Direct组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Delphi XE4,我通常IdHttp.POST印使用POST请求的网站,



这时候,每当我尝试POST请求我get 错误:您的浏览器未发送正确的数据。



正确的数据,我使用IOHandler和CookieManager。



已经处理了这几天(字面上)



这里是代码(代码中的网站) :

  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;



(该getParamLge和GetInput功能,只是简单的复制和POS功能,从GET输入反应中获取价值)。



我想可能需要cookie,所以我在开头添加了这个:

  Cookie.CookieCollection.Clear; 
Cookie.CookieCollection.AddClientCookies('CFID = 21531887; CFTOKEN = 20369251; DH = 20130709111845,1920x1080,{TS'2013年7月9日六时18分58秒''}; __utma = 90161412.436822896.1373368451.1373368451.1373368451.1 ; __utmb = 90161412.11.10.1373368451; __utmc = 90161412; __utmz = 90161412.1373368451.1.1'+'= utmcsr(直接)| utmccn =(直接)| utmcmd =(无); __asc = 06ff77ad13fc32381fd1f5d6405; __auc = 06ff77ad13fc32381fd1f5d6405; __atuvc = 4% 7C28; MS =平');

但一切都徒劳。


解决方案

我很肯定我张贴了正确的数据。


因为它不工作 - 显然你没有(或Delphi不 - 对服务器没有区别)。



您应该开始通常的调试循环:


  1. 观察参考工作行为。

  2. 观察您的计划行为

  3. 找出差异

  4. 消除差异

  5. 检查程序是否正常工作

参考实现将是一些 WWW浏览器使用网站:Opera,Chrome,Firefox,MS IE等。




  • 观测工具是一些 HTTP嗅探器像Wireshark的或OmniPacket或Microsoft网络监视器或其他,但是这锅匠们用的操作系统上工作,而深层次的。

  • 或者它可以是GUI的本地代理,如Proxomitron或Membrane Monitor - 但是这将需要特别设置的程序和浏览器,路由他们的流量通过本地代理。



然后你应该阅读关于HTTP,从维基百科的浅观察开始,然后打开相关的RFC文档(HTTP协议的不同部分的规范),这样你就可以理解观察到的差异意味着如何解决它们。例如许多人使用POST请求时,他们实际应该使用GET请求等。



您想要调试HTTP程序,但对于这个HTTP日志,workign和borken,和你的问题缺乏他们。更重要的是,很可能你可以解决你的自我,只是带来你的程序的HTTP日志符合RFC理论和工作的浏览器实践。


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.

解决方案

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.

这篇关于WWW服务器报告错误后POST请求由Delphi中的Direct Direct组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆