简体   繁体   中英

sending xml data using post request

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

Above URL is shipstation API document for fetching order,creating orders,updating and deleting.

I want to use create order API which is POST request ,where order data entries are sent to shipstation using xml.

My question is how i can send xml data to shipstation using POST request using Python?

Since iam not able to post entire code on this page ,so please refer this URL to see post request for creating order-

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. 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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