所以我已经使用 pythons 请求库向服务器发出请求。代码看起来像这样(它使用了一个适配器,所以它需要匹配一个特定的模式)
def getRequest(self, url, header):
"""
implementation of a get request
"""
conn = requests.get(url, headers=header)
newBody = conn.content
newHeader = conn.headers
newHeader['status'] = conn.status_code
response = {"Headers" : newHeader, "Body" : newBody.decode('utf-8')}
self._huddleErrors.handleResponseError(response)
return response
我正在解析的标头参数是这个
{'Authorization': 'OAuth2 handsOffMyToken', 'Accept': 'application/vnd.huddle.data+json'}
但是我从服务器收到了一个 xml 响应。检查提琴手后,我看到正在发送的请求是:
Accept-Encoding: identity
Accept: */*
Host: api.huddle.dev
Authorization: OAuth2 HandsOffMyToken
Accept: application/vnd.huddle.data+json
Accept-Encoding: gzip, deflate, compress
User-Agent: python-requests/1.2.3 CPython/3.3.2 Windows/2008ServerR2
正如我们所见,有 2 个 Accept 标头!requests 库正在添加此 Accept:* / * 标头,该标头正在从服务器中删除。有谁知道我怎么能阻止这个?