使用 cURL 和 PHP 的 UPS API...格式良好的 XML 问题

发布于 2024-12-02 06:45:44 字数 2500 浏览 0 评论 0原文

UPS 服务器不断向我提供此响应:

HTTP/1.1 200 OK
Server: Apache
Content-Length: 429
X-Powered-By: Servlet/2.5 JSP/2.1
Content-Type: application/xml
Expires: Wed, 31 Aug 2011 21:28:12 GMT
Cache-Control: max-age=0, no-cache, no-store
Pragma: no-cache
Date: Wed, 31 Aug 2011 21:28:12 GMT
Connection: keep-alive

出现此错误:

<AddressValidationResponse>
   <Response>
      <TransactionReference>
         <XpciVersion>1.0001</XpciVersion>
      </TransactionReference>
      <ResponseStatusCode>0</ResponseStatusCode>
      <ResponseStatusDescription>Failure</ResponseStatusDescription>
      <Error>
         <ErrorSeverity>Hard</ErrorSeverity>
            <ErrorCode>10001</ErrorCode>
            <ErrorDescription>The XML document is not well formed</ErrorDescription>
      </Error>
   </Response>
</AddressValidationResponse>

这是我发送到服务器的 PHP 代码。是否有我遗漏和忽略的错误?

$data = '<?xml version=\"1.0\" ?>
                <AccessRequest xml:lang=\"en-US\">
                    <AccessLicenseNumber>$this->AccessLicenseNumber</AccessLicenseNumber>
                    <UserId>$this->UserId</UserId>
                    <Password>$this->Password</Password>
                </AccessRequest>
                <?xml version=\"1.0\" ?>
                <AddressValidationRequest xml:lang=\"en-US\">
                    <Request>
                        <TransactionReference>
                            <XpciVersion>1.0001</XpciVersion>
                        </TransactionReference> 
                        <RequestAction>XAV</RequestAction> 
                        <RequestOption>3</RequestOption>
                    </Request>
                    <AddressKeyFormat>
                        <AddressLine>$address</AddressLine>
                        <PoliticalDivision2>$city</PoliticalDivision2>
                        <PoliticalDivision1>$state</PoliticalDivision1>
                        <PostcodePrimaryLow>$zip</PostcodePrimaryLow>
                        <CountryCode>US</CountryCode>
                    </AddressKeyFormat>
                </AddressValidationRequest>';

任何帮助将不胜感激。谢谢。

The UPS server keeps giving me this response :

HTTP/1.1 200 OK
Server: Apache
Content-Length: 429
X-Powered-By: Servlet/2.5 JSP/2.1
Content-Type: application/xml
Expires: Wed, 31 Aug 2011 21:28:12 GMT
Cache-Control: max-age=0, no-cache, no-store
Pragma: no-cache
Date: Wed, 31 Aug 2011 21:28:12 GMT
Connection: keep-alive

with this error:

<AddressValidationResponse>
   <Response>
      <TransactionReference>
         <XpciVersion>1.0001</XpciVersion>
      </TransactionReference>
      <ResponseStatusCode>0</ResponseStatusCode>
      <ResponseStatusDescription>Failure</ResponseStatusDescription>
      <Error>
         <ErrorSeverity>Hard</ErrorSeverity>
            <ErrorCode>10001</ErrorCode>
            <ErrorDescription>The XML document is not well formed</ErrorDescription>
      </Error>
   </Response>
</AddressValidationResponse>

Here is the PHP code I am sending to the server. Is there an error that I am missing and overlooking?

$data = '<?xml version=\"1.0\" ?>
                <AccessRequest xml:lang=\"en-US\">
                    <AccessLicenseNumber>$this->AccessLicenseNumber</AccessLicenseNumber>
                    <UserId>$this->UserId</UserId>
                    <Password>$this->Password</Password>
                </AccessRequest>
                <?xml version=\"1.0\" ?>
                <AddressValidationRequest xml:lang=\"en-US\">
                    <Request>
                        <TransactionReference>
                            <XpciVersion>1.0001</XpciVersion>
                        </TransactionReference> 
                        <RequestAction>XAV</RequestAction> 
                        <RequestOption>3</RequestOption>
                    </Request>
                    <AddressKeyFormat>
                        <AddressLine>$address</AddressLine>
                        <PoliticalDivision2>$city</PoliticalDivision2>
                        <PoliticalDivision1>$state</PoliticalDivision1>
                        <PostcodePrimaryLow>$zip</PostcodePrimaryLow>
                        <CountryCode>US</CountryCode>
                    </AddressKeyFormat>
                </AddressValidationRequest>';

Any help would be greatly appreciated. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国粹 2024-12-09 06:45:44

您必须使用 " 而不是 ' 来包装您的 xml,如下所示:

$data="<?xml...";

PHP 仅替换 " 内的变量

You have to use " instead of ' to wrap your xml, like this:

$data="<?xml...";

PHP only replaces variables inside of "

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文