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 = <<<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> <options> <option> <option-code>DC</option-code> </option> </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>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)