为什么我的 Put 请求失败?
使用Python 2.5和httplib......
我确实是一个Python新手......但这看起来很简单,为什么这不起作用?
httpConn = HTTPConnection('127.0.0.1', 44789)
httpConn.request('PUT','/ShazaamMon/setmfgdata.cgi?serial=', hwSerialNum)
httpResp = httpConn.getresponse()
xmlResp = httpResp.read()
httpConn.close()
它返回以下响应:
有人有任何线索吗???
Using Python 2.5 and httplib......
I am admittedly a python novice.....but this seems straight forward, why doesn't this work?
httpConn = HTTPConnection('127.0.0.1', 44789)
httpConn.request('PUT','/ShazaamMon/setmfgdata.cgi?serial=', hwSerialNum)
httpResp = httpConn.getresponse()
xmlResp = httpResp.read()
httpConn.close()
it returns the following response: <HTML><HEAD><TITLE>HTTP 404.......
Any clues anyone???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你应该用 GET 替换 PUT。
您应该考虑清理输入,trye
I think you should replace PUT with GET.
You should consider sanitizing the input, trye
HTTP 404
表示您请求的资源不存在。您确定网址正确吗?此外,您在请求正文(
request()
的第三个参数)中放入了一个我认为是请求参数的变量。尝试以下操作:
或者也许(如果需要 GET 而不是 PUT):
HTTP 404
means that the resource you requested does not exist. Are you sure that the URL is correct?Moreover, you put in the body of the request (third parameter of
request()
) a variable that I think is a parameter of the request.Try the following:
or maybe (if GET is required instead of PUT):
@Angelom 的答案简洁且正确。有关在 urllib 和 urllib2 中使用 PUT 的很好的示例解释,请尝试 http: //www.voidspace.org.uk/python/articles/urllib2.shtml#data。
@Angelom's answer is concise and correct. For a nice example-filled explanation of using PUT in urllib and urllib2 try http://www.voidspace.org.uk/python/articles/urllib2.shtml#data.