背景關系:我正在嘗試向 UPS 的 ShipAccept api 發送測驗請求。我收到一條錯誤訊息,告訴我 xml 檔案格式不正確。我發送的實際請求包含所有必需的資訊,這只是相同的格式。
<AccessRequest xml:lang="en-US">
<AccessLicenseNumber>Your_License</AccessLicenseNumber>
<UserId>Your_ID</UserId>
<Password>Your_Password</Password>
</AccessRequest>
</?xml version="1.0"?>
<ShipmentConfirmRequest xml:lang="en-US">
<Request>
<TransactionReference>
<CustomerContext>Customer Comment</CustomerContext>
</TransactionReference>
<RequestAction>ShipConfirm</RequestAction>
<RequestOption>validate</RequestOption>
</Request>
<LabelSpecification>
<LabelPrintMethod>
<Code>GIF</Code>
<Description>gif file</Description>
</LabelPrintMethod>
<HTTPUserAgent>Mozilla/4.5</HTTPUserAgent>
<LabelImageFormat>
<Code>GIF</Code>
<Description>gif</Description>
</LabelImageFormat>
</LabelSpecification>
<Shipment>
<RateInformation>
<NegotiatedRatesIndicator/>
</RateInformation>
<Description/>
<Shipper>
<Name>Shipper Name</Name>
<PhoneNumber>1234567890</PhoneNumber>
<ShipperNumber>Ship Number</ShipperNumber>
<TaxIdentificationNumber>1234567877</TaxIdentificationNumber>
<Address>
<AddressLine1>Address Line</AddressLine1>
<City>City</City>
<StateProvinceCode>MD</StateProvinceCode>
<PostalCode>21093</PostalCode>
<PostcodeExtendedLow></PostcodeExtendedLow>
<CountryCode>US</CountryCode>
</Address>
</Shipper>
<ShipTo>
<CompanyName>Ship To Company Name</CompanyName>
<AttentionName>Ship To Attn Name</AttentionName>
<PhoneNumber>97225377171</PhoneNumber>
<Address>
<AddressLine1>Address Line</AddressLine1>
<City>City</City>
<StateProvinceCode>FL</StateProvinceCode>
<PostalCode>32960</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</ShipTo>
<ShipFrom>
<CompanyName>Ship From Company Name</CompanyName>
<AttentionName>Ship From Attn Name</AttentionName>
<PhoneNumber>1234567890</PhoneNumber>
<TaxIdentificationNumber>1234567877</TaxIdentificationNumber>
<Address>
<AddressLine1>Address Line</AddressLine1>
<City>City</City>
<StateProvinceCode>MD</StateProvinceCode>
<PostalCode>21093</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</ShipFrom>
<PaymentInformation>
<Prepaid>
<BillShipper>
<AccountNumber>Ship Number</AccountNumber>
</BillShipper>
</Prepaid>
</PaymentInformation>
<Service>
<Code>02</Code>
<Description>2nd Day Air</Description>
</Service>
<Package>
<PackagingType>
<Code>02</Code>
<Description>Customer Supplied</Description>
</PackagingType>
<Description>Package Description</Description>
<ReferenceNumber>
<Code>00</Code>
<Value>Package</Value>
</ReferenceNumber>
<PackageWeight>
<UnitOfMeasurement/>
<Weight>60.0</Weight>
</PackageWeight>
<LargePackageIndicator/>
<AdditionalHandling>0</AdditionalHandling>
</Package>
</Shipment>
</ShipmentConfirmRequest>
另外,縮進對xml很重要嗎?我的縮進錯誤的事實可能是檔案格式不正確的原因嗎?我對 xml 沒有任何經驗,但不幸的是,UPS api 接受大多數東西作為 json 除了運輸部件。非常感謝您提前為我提供的任何幫助!
編輯:提供的代碼是他們自己的正確請求示例,所以我很困惑。
uj5u.com熱心網友回復:
一個 XML 檔案只能有一個根。您在這里看到的是兩個XML 檔案,它們在第二個檔案的宣告中與一個錯字連接在一起。
</AccessRequest> <-- end of the root element of the 1st doc
</?xml version="1.0"?> <-- Probably an XML declaration of the 2nd doc.
Shouldn't have the slash.
<ShipmentConfirmRequest xml:lang="en-US">
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/429364.html
