以编程方式POST'ing表单不在做我的浏览器正在做什么。为什么? [英] Programatically POST'ing a form is not doing what my browser is doing. Why?

查看:141
本文介绍了以编程方式POST'ing表单不在做我的浏览器正在做什么。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试以编程方式在我没有的网站上提交表单。我试图模拟手动使用网络浏览器做什么。我使用HTTP库发出HTTP POST请求。



出于某种原因,我不知道我得到了不同的结果(错误,不同的响应, ...),当我以编程方式提交表单时,与在Web浏览器中手动提交相比。



这怎么可能,我怎么才能找出我犯的错误?



这个问题是有意识的语言和库不可知的。我要求提供调试这些问题的一般程序。 解决方案

这个问题的所有实例都是相同的。以下是如何解决所有问题:



您发布的网站无法区分不同的客户。它无法确定您使用的是Web浏览器还是HTTP库。因此,只有您发送的内容对于服务器决定如何应对

如果您观察到来自这意味着你正在发送不同的请求。



您可能必须正确发送一些重要的内容:




  • URL

  • 动词( GET / code>)

  • 标题:主机用户代理 Content-Length

  • Cookies( Cookie 和<$ c

    $ b

    p> 使用像Fiddler这样的HTTP嗅探器来捕获您正在以编程方式发送的内容以及您的浏览器发送的内容。比较差异请求。逐个消除差异,看看哪一个引起了问题。您可以拖动一个HTTP请求到Composer窗口中,以便修改和重新发布它。



    如果您真的消除了所有差异,仍然无法获得不同的结果在手册和程序化请求之间。

    I'm trying to programmatically submit a form on a web site that I do not own. I'm trying to simulate what I would manually do with a web browser. I am issuing an HTTP POST request using an HTTP library.

    For a reason that I don't know I am getting a different result (an error, a different response, ...) when I programmatically submit the form compared to a manual submission in a web browser.

    How can that be and how can I find out what mistake I have made?

    This question is intentionally language and library agnostic. I'm asking for the general procedure for debugging such issues.

    解决方案

    All instances of this problem are equivalent. Here is how to resolve all of them:

    The web site you are posting to cannot tell different clients apart. It cannot find out whether you are using a web browser or an HTTP library. Therefore, only what you send matters for the decision of the server on how to react.

    If you observe different responses from the server this means that you are sending different requests.

    A few important things that you probably have to send correctly:

    • URL
    • Verb (GET or POST)
    • Headers: Host, User-Agent, Content-Length
    • Cookies (the Cookie and Set-Cookie headers)
    • The request body

    Use an HTTP sniffer like Fiddler to capture what you are programmatically sending and what your browser is sending. Compare the requests for differences. Eliminate the differences one by one to see which one caused the problem. You can drag an HTTP request into the Composer Window to be able to modify and reissue it.

    It is impossible to still get a different result if you truly have eliminated all differences between the manual and the programmatic requests.

    这篇关于以编程方式POST'ing表单不在做我的浏览器正在做什么。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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