gpt4 book ai didi

Python 请求 - POST 需要隐藏输入吗?

转载 作者:太空宇宙 更新时间:2023-11-03 18:48:37 24 4
gpt4 key购买 nike

假设我有一个如下所示的表单,其中包含一些隐藏的输入:

<form id="myForm" method="post" action="http://www.X.Y/index.php?page=login>

<input type="hidden" name="Hidden1" value="" />
<input type="hidden" name="Hidden2" value="abcdef" />
<input type="hidden" name="Hidden3" value="1234" />
<input type="text" name="firstTextBox" value=""/>
<input type="button" name="clickButton" value="OK"/>
</form>

我将通过以下方式运行 python POST 请求:

import requests
s = requests.Session()

postRequest = {'Hidden1': '',
'Hidden2': 'abcdef',
'Hidden3': '',
'firstTextBox': 'Typed in first text box',
'clickButton': 'OK'
}

s.auth = HttpNtlmAuth(username, password)
s.post(url, data=manufacturingRequest)

我的问题是,我是否必须将隐藏输入包含在 postRequest 字典中?如果省略 type 属性值为“hidden”的元素,是否可以提交 POST 请求?

如果网站的值设置为空字符串(例如 myForm 中的 Hidden1 元素),那么即使网站具有隐藏输入,其用途又是什么?上面的例子。

编辑 - 下半场

经过一些研究,我注意到每次访问该页面时,一些隐藏元素都有不同的值

<input type="hidden" name="__REQUESTDIGEST" id="__REQUESTDIGEST" value="0xEB8842A77FE88CA990D2EA0D4BAA0392C13FCEF3DCF3250EBF575B90C03BFBC9AD4D61180DA81DF7B09144BBB04BBFF1565C2ADEE650CCC3D81B149034E711A4,18 Sep 2013 19:48:18 -0000" />

有时间戳

以及

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="SOME+VERY+LONG+RSA+STRING">

它有一些类似 RSA 的字符串作为其值

结果是,如果我尝试提交具有与这些值不同的值的 POST,该网站会给出 200 错误代码。这些是网站的额外安全措施吗?

..如果是这样,我如何以编程方式发送 POST 请求,考虑不断变化的元素值?

最佳答案

did I HAVE to include the hidden inputs in the postRequest dictionary?

不,您不必包含隐藏的输入。没有法律、条约或标准要求您包含任何特定的输入元素。

另一方面,如果您未能包含它们,那么您所做的事情与浏览器所做的不同,网站可能会注意到这一点。

Can you submit a POST request if you omit elements with a type attribute value of "hidden"?

是的,可以。您还可以省略 textbutton 类型的元素。网站如何响应完全取决于它。

What's the purpose of websites even having hidden inputs if their values are set to EMPTY string,

网站开发者的目的实际上取决于他们。您可以询问您尝试提交的网站的开发人员。

一个可能的目的是确定哪个表单正在提交。

<小时/>

Are these extra security measures for the website?

再次询问网站的所有者。它可能是安全性,可能是 session 管理,或者可能包含您的偏好。

..and IF SO, how can I programmatically send POST requests, accounting for the changing element values?

获取包含表单的页面,解析该页面,然后使用指定的表单变量提交表单。

关于Python 请求 - POST 需要隐藏输入吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18881519/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com