我如何使用urllib3发布XML

问题描述 投票:0回答:1

我使用支持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)
python xml urllib3
1个回答
0
投票

您需要使用body参数导入:

send_message = http.request('POST', 'http://192.168.8.1/api/sms/send-sms', body=data, headers={'__RequestVerificationToken': token, 'Content-Type': 'application/xml'})
© www.soinside.com 2019 - 2024. All rights reserved.