简体   繁体   English

相当于 curl TRACE 的 Python

[英]Python equivalent for curl TRACE

Is there a python equivalent for checking if a host accepts the trace method?是否有用于检查主机是否接受跟踪方法的 python 等效项?

curl -sIX TRACE neopets.com

Note, I'm not trying to get a request traceback, I'm also not trying to get my raw request.请注意,我不是要获取请求回溯,也不是要获取我的原始请求。 I'm trying to verify if a webserver supports the TRACE method.我正在尝试验证网络服务器是否支持 TRACE 方法。

https://curl.trillworks.com/ translates the command to: https://curl.trillworks.com/将命令转换为:

requests.head('http://neopets.com') but it doesn't seem to get me the same result as the curl. requests.head('http://neopets.com')但它似乎没有得到与 curl 相同的结果。

EDIT: I guess I have to construct the request编辑:我想我必须构建请求

req = requests.Request('TRACE', 'https://google.com')
r = req.prepare()
s = requests.Session()
s.send(r)

Since you just want to check if the TRACE method is accepted, you can use the OPTIONS method instead.由于您只想检查 TRACE 方法是否被接受,因此您可以改用 OPTIONS 方法。 The available methods will be returned in the Allow header.可用方法将在Allow标头中返回。

import requests

response = requests.options('http://google.com/')
print(response.headers['Allow'])

>> GET, HEAD

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM