簡體   English   中英

使用post請求發送xml數據

[英]sending xml data using post request

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

上面的URL是shipstation API文檔,用於獲取訂單,創建訂單,更新和刪除。

我想使用創建訂單API,它是POST請求,其中訂單數據條目使用xml發送到shipstation。

我的問題是如何使用Python使用POST請求將xml數據發送到shipstation?

由於我無法在此頁面上發布整個代碼,因此請參閱此URL以查看創建訂單的發布請求 -

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

謝謝

你應該這樣試試

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

使用Python 請求模塊。 您可以在快速入門頁面上找到一些示例:

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

要么

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

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

在這里查看更多: 如何使用請求庫發送xml正文?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM