# coding:utf-8

import requests  

url = "http://httpbin.org/post"

# python3字符串换行,在右边加个反斜杠

body ='<?xml version="1.0" encoding = "UTF-8"?>' \ '<COM>' \ '<REQ name="哈哈哈">' \ '<USER_ID>yoyoketang</USER_ID>' \

     '<COMMODITY_ID>123456</COMMODITY_ID>' \ '<SESSION_ID>absbnmasbnfmasbm1213</SESSION_ID>' \

    '</REQ>' \ '</COM>'

# 遇到编码报错时候,对body进行encode

r = requests.post(url, data=body.encode("utf-8"))

print(r.text)

=========================================

# coding:utf-8

import os

curpath = os.path.dirname(os.path.realpath(__file__)) #获取当前执行脚本的绝对路径

xmlpath = os.path.join(curpath, "body1_xml") # 将多个路径组合后返回

with open(xmlpath, encoding="utf-8") as fp:

   body = fp.read()

# 读取xml文件

print(body)

相关文章:

  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2021-11-23
  • 2021-09-18
  • 2021-09-25
  • 2022-01-06
  • 2021-05-23
猜你喜欢
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-05-19
  • 2022-03-09
相关资源
相似解决方案