传递数据为xml形式的post请求
请求体内容:
<?xml version=“1.0” encoding = “UTF-8”?> <COM> <REQ name="平常心"> <USER_ID>pcx</USER_ID> <COMMODITY_ID>123456</COMMODITY_ID> <SESSION_ID>absbnmasbnfmasbm1213</SESSION_ID> </REQ> </COM>
代码:
import requests #请求内容为xml的post请求 url = "http://httpbin.org/post" # python3字符串换行,在右边加个反斜杠 body = '<?xml version="1.0" encoding = "UTF-8"?>' '<COM>' '<REQ name="平常心">' '<USER_ID>pcx</USER_ID>' '<COMMODITY_ID>123456</COMMODITY_ID>' '<SESSION_ID>absbnmasbnfmasbm1213</SESSION_ID>' '</REQ>' '</COM>' response = s.post(url, data=body.encode("utf-8"),verify=False) print(response.text)
运行结果: