我需要對服務器進行一些測試,以便我想對內容長度進行硬編碼,而不希望請求庫計算內容長度。設置請求庫內容長度
我寫至今的代碼看起來是這樣的:
date = time.strftime("%a, %d %b %Y %H:%M:%S GMT",time.gmtime(time.time()))
sample_header = {
"Host": "xyz.xyz.zyz.com",
"Content-Type": "application/json; charset=utf-8",
"Date": date
# "Authorization": "not_specified"
}
sample_payload = {
"ci":{
"pev":1,
"affid":"243324",
"sdkv":"My SDK Version",
"prn":"My Security Product",
"pv":"1.0.1",
"cliid":"4fe836859578e81ae5b0a061d6949634",
"rid":234343
},
"q":[{"op":"url","url":"http://www.yahoo.com"}]
}
def test_1677(self):
self.tc_id="gtirest-1677"
s = requests.Session()
req = requests.Request('POST', url, headers=sample_header, data=json.dumps(sample_payload))
prepared = req.prepare()
# del prepared.headers['Content-Lenght']
del prepared.headers['Content-Length']
prepared.headers['Content-Lenght'] = 99999
response = s.send(prepared)
print "Response code"
print response.status_code
print response.text
print response.request.headers
它給400錯誤的請求,但是當我發送類似內容長度它給413實體過大,這是對的,我怎麼能acheive的請求庫中也一樣。
我做Wireshark的捕獲,它顯示了以下內容:
隨着請求庫:
,捲曲:
爲什麼在請求庫它給400錯誤的請求。我可以看到有效載荷現在正在提出正確的請求。
爲什麼在請求庫中它提供了400個錯誤的請求。我可以看到有效載荷現在正在提出正確的請求。 – 2015-02-06 14:33:22