我使用支持Hilink的GSM调制解调器创建了一个短信网关。我坚持张贴XML。第一步是获取会话和令牌。第二。与令牌传递到头。它将被授予访问权限以发送消息。但是,如何通过urllib3传递XML数据?
import urllib3
import xml.etree.ElementTree as XML
http = urllib3.PoolManager()
response_body = http.request('GET', 'http://192.168.8.1/api/webserver/SesTokInfo')
tree = XML.ElementTree(XML.fromstring(response_body.data))
root = tree.getroot()
token = root[1].text
data="<?xml version='1.0' encoding='UTF-8'?><request><Index>-1</Index><Phones><Phone>Number</Phone></Phones><Sca></Sca><Content>test</Content><Length>4</Length><Reserved>1</Reserved><Date>-1</Date></request>"
send_message = http.request('POST', 'http://192.168.8.1/api/sms/send-sms', data=data, headers={'__RequestVerificationToken': token, 'Content-Type': 'application/xml'})
print(send_message.status)
您需要使用body
参数导入:
send_message = http.request('POST', 'http://192.168.8.1/api/sms/send-sms', body=data, headers={'__RequestVerificationToken': token, 'Content-Type': 'application/xml'})