【发布时间】:2012-07-04 13:33:21
【问题描述】:
我在网上找到了这个脚本:
import httplib, urllib
params = urllib.urlencode({'number': 12524, 'type': 'issue', 'action': 'show'})
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
conn = httplib.HTTPConnection("bugs.python.org")
conn.request("POST", "", params, headers)
response = conn.getresponse()
print response.status, response.reason
302 Found
data = response.read()
data
'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
conn.close()
但我不明白如何在 PHP 中使用它,或者 params 变量中的所有内容是什么,或者如何使用它。我可以帮我解决这个问题吗?
【问题讨论】:
-
发布请求只是发布请求,不管服务器端是什么。
-
这会发送一个 POST 请求。然后服务器以 302(重定向)标头响应您的 POST。究竟出了什么问题?
-
这个脚本看起来不像 python3.2 兼容
-
python3 等价于这个例子可能是:pastebin.com/Rx4yfknM
-
我建议安装firefox的
live http header插件,然后在firefox中打开你的url,然后在live http header插件中查看url的request/response,这样你就会明白params and headers在你的代码。
标签: urllib python-2.x httplib