本文介绍了PHP xml插入字符,例如-错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dear Experts,

I am trying to send address information to Canada Post using xml code with PHP

When ever I send data I get this error message:

HTTP Response Status: 400 Error Code: 1623 Error Msg: A name or address field contains an invalid character such as |.

This is a data I am trying to send $shipping_city = "St. Philip's";

This is the xml code I use:

<pre lang="PHP"><pre lang="PHP">$xmlRequest = <<&lt;XML

<?xml version="1.0" encoding="UTF-8"?>
<shipment xmlns="http://www.canadapost.ca/ws/shipment">
    <group-id>{$groupId}</group-id>
    <requested-shipping-point>{$requestedShippingPoint}</requested-shipping-point>
    <expected-mailing-date>{$mailingDate}</expected-mailing-date>
    <delivery-spec>
        <service-code>DOM.EP</service-code>
            <sender>
                <name>ahhahah</name>
                <company>hahha Importers</company>
                <contact-phone>613 611 1112</contact-phone>
                <address-details>
                    <address-line-1>1501 Liiight Ave. Bay 7</address-line-1>
                    <city>OTTAWA</city>
                    <prov-state>ON</prov-state>
                    <country-code>CA</country-code>
                    <postal-zip-code>K1T1M5</postal-zip-code>
                </address-details>
            </sender>
            <destination>
                <name>$name</name>
                    <address-details>
                    <address-line-1>$address1</address-line-1>
                    <address-line-2>$address2</address-line-2>
                    <city>$shipping_city</city>
                    <prov-state>$shipping_state</prov-state>
                    <country-code>$shipping_country_code</country-code>
                    <postal-zip-code>$shipping_zip</postal-zip-code>
                </address-details>
            </destination>
        &lt;options>
            &lt;option>
                &lt;option-code>DC&lt;/option-code>
            &lt;/option>
        &lt;/options>
        <parcel-characteristics>
            <weight>0.4</weight>
            <dimensions>
                <length>6</length>
                <width>3</width>
                <height>3</height>
            </dimensions>
            <unpackaged>false</unpackaged>
            <mailing-tube>false</mailing-tube>
        </parcel-characteristics>
        <notification>
            <email>$email</email>
            <on-shipment>true</on-shipment>
            <on-exception>false</on-exception>
            <on-delivery>true</on-delivery>
        </notification>
        <print-preferences>
            <output-format>4x6</output-format>
        </print-preferences>
        <preferences>
            <show-packing-instructions>false</show-packing-instructions>
            <show-postage-rate>false</show-postage-rate>
            <show-insured-value>true</show-insured-value>
        </preferences>
        <settlement-info>
            <contract-id>{$contractId}</contract-id>
            <intended-method-of-payment>Account</intended-method-of-payment>
        </settlement-info>
    </delivery-spec>
</shipment>
XML;

$curl = curl_init($service_url); // Create REST Request
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_CAINFO, realpath(dirname($argv[0])) . '/cacert.pem'); // Signer Certificate in PEM format
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xmlRequest);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/vnd.cpc.shipment-v2+xml', 'Accept: application/vnd.cpc.shipment-v2+xml'));
$curl_response = curl_exec($curl); // Execute REST Request
if(curl_errno($curl)){
    echo 'Curl error: ' . curl_error($curl) . "\n";
}

echo 'HTTP Response Status: ' . curl_getinfo($curl,CURLINFO_HTTP_CODE) . "\n";

curl_close($curl);
</pre>




有人可以指导我停止错误消息并将数据发送到加拿大后吗

非常感谢您.




Can someone guide me to stop the error message and send data to Canada post

Thank you very much

推荐答案




这篇关于PHP xml插入字符,例如-错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 07:51