Click here to Skip to main content
13,342,876 members (57,091 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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="">
                <company>hahha Importers</company>
                <contact-phone>613 611 1112</contact-phone>
                    <address-line-1>1501 Liiight Ave. Bay 7</address-line-1>

$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_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
    echo 'Curl error: ' . curl_error($curl) . "\n";

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


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

Thank you very much
Posted 2-Oct-12 16:38pm
Updated 2-Oct-12 18:05pm
Yes... it looks like Canada post system has hallucination... I wonder if they could have some stupid bug.
Did you try to send more realistic name, for an attempt of a workaround? Seriously, it could be some stupid bug which reports your "ahhahah" in a weird way. What if it checks for proper capitalization or something like that?

The fact that the server-side software is pretty bad is visible with a unarmed eye. For example, reasonable software won't tell you "a name or address field", it will tell what exactly field it was.
However, it could be $address1, $address2 or something. Please output all variables (you don't tell us the values) to check them up. It could be another source of the bug, in this case -- yours.
Member 9478973 2-Oct-12 23:10pm
Dear SA, Thank you very much for your comments. I am sorry, I may be did not explain my issue. "ahhahah" is just a name I put to avoid putting my company personal's name. Error show up because of $shipping_city data has a '(apostrophe) Do you know a way to include apostrophe in $shipping_city data and send it to Canada Post. Thank you very much again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180111.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100