0

上下文:我正在尝试向 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 除了运输部件。非常感谢您提前为我提供的任何帮助!

编辑:提供的代码是他们自己的正确请求示例,所以我很困惑。

4

1 回答 1

2

一个 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">
于 2022-02-20T19:55:28.430 回答