亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python post request拋出“ 400 Bad Request”

python post request拋出“ 400 Bad Request”

慕容森 2021-04-06 13:14:00
我正在嘗試執行以下腳本,在該腳本中嘗試發送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')
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 449 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號