我正在嘗試執行以下腳本,在該腳本中嘗試發送POST請求。我已經替換了標頭部分中的一些值,以便將其發布到此處。我遇到的問題與從xmlFile.xml中讀取的請求正文有關。文件與我的腳本位于同一目錄中。XML寫在一行中,并從下一行開始:<?xml version="1.0"?> 能否請你幫忙?我不明白為什么它會返回400 Bad Request。XML可以單獨正常運行,但不能在py腳本中運行。#!/usr/bin/pythonimport httplibdef do_request(xmlFile): request = open(xmlFile, "r").read() conn = httplib.HTTPConnection("ipAddress", port) conn.putrequest("POST", "selector HTTP/1.1") conn.putheader("Content-Length", "%d" % len(request)) conn.putheader("Content-Type", "text/xml") conn.putheader("Host", "ipAddress") conn.putheader("User-Agent", "userAgent") conn.endheaders() conn.send(request) response = conn.getresponse() print(response.status, response.reason) data = response.read() print(data) conn.close()do_request('xmlFile.xml')
添加回答
舉報
0/150
提交
取消