简体   繁体   English

使用post请求发送xml数据

[英]sending xml data using post request

http://api.shipstation.com/Order-Resource.ashx http://api.shipstation.com/Order-Resource.ashx

Above URL is shipstation API document for fetching order,creating orders,updating and deleting. 上面的URL是shipstation API文档,用于获取订单,创建订单,更新和删除。

I want to use create order API which is POST request ,where order data entries are sent to shipstation using xml. 我想使用创建订单API,它是POST请求,其中订单数据条目使用xml发送到shipstation。

My question is how i can send xml data to shipstation using POST request using Python? 我的问题是如何使用Python使用POST请求将xml数据发送到shipstation?

Since iam not able to post entire code on this page ,so please refer this URL to see post request for creating order- 由于我无法在此页面上发布整个代码,因此请参阅此URL以查看创建订单的发布请求 -

http://api.shipstation.com/Order-Resource.ashx http://api.shipstation.com/Order-Resource.ashx

Thanks 谢谢

you should try like this 你应该这样试试

def frame_xml(AddressVerified,AmountPaid):
    xml_data = """<?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"  xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/ metadata" xmlns="http://www.w3.org/2005/Atom">
    <category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" term="SS.WebData.Order" />
     <title />
     <author>
     <name />
     </author>
     <id />
     <content type="application/xml">
     <m:properties>
       <d:AddressVerified m:type="Edm.Byte">%s</d:AddressVerified>
       <d:AmountPaid m:type="Edm.Decimal">%s</d:AmountPaid>
     </m:properties>
    </content>
   </entry>"""%(AddressVerified,AmountPaid)
   return xml_data

headers = {'Content-Type': 'application/xml'}
xml_data = frame_xml('AddressVerified','AmountPaid')
print requests.post('https://data.shipstation.com/1.2/Orders', data=xml_data, headers=headers).text

Use Python requests module. 使用Python 请求模块。 Some examples you can find on quick-start page: 您可以在快速入门页面上找到一些示例:

>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.post("http://httpbin.org/post", data=payload)
>>> print r.text
    ...

Or 要么

>>> url = 'http://httpbin.org/post'
>>> files = {'file': open('report.xls', 'rb')}

>>> r = requests.post(url, files=files)
    ...

See more here: How can I send an xml body using requests library? 在这里查看更多: 如何使用请求库发送xml正文?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM