python发送.xml格式的post请求;
方式一:import requestsurl="https://httpbin.org/post"body=‘<?xml version=“1.0” encoding = “UTF-8”?>‘\ ‘<COM>‘\ ‘<REQ name="北京-宏哥">‘\ ‘<USER_ID>bjhongge</USER_ID>‘\ ‘<COMMODITY_ID>123456</COMMODITY_ID>‘\ ‘<SESSION_ID>absbnmasbnfmasbm1213</SESSION_ID>‘\ ‘</REQ>‘\ ‘</COM>‘a=requests.post(url,data=body.encode("utf-8"))print(a.text)方式二:读取.xml文件的内容;
#encoding=‘utf-8import requestsurl="https://httpbin.org/post"r=open(‘bodytext.xml‘).read()#print(r)a=requests.post(url,data=r.encode("utf-8"))print(a.text)