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


UPS API using cURL and PHP...well-formed XML issue

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>';

任何帮助都将非常感激。谢谢你。

你必须使用"而不是'来包装你的xml,像这样:

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

PHP只替换"里面的变量