Assist with USPS API using PHP Curl
<p>Hello I am trying to do API call to USPS API using PHP Curl.</p>

<p>I get the following response:</p>

<pre><code>[Number] =&gt; 80040B19
[Description] =&gt; XML Syntax Error: Please check the XML request to see if it can be parsed.
[Source] =&gt; USPSCOM::DoAuth
</code></pre>

<p>I put together my code for the API call from some sample code on here and also the sample on the USPS site; but cannot get it to work (getting error above); here is my code:</p>

<pre><code>$input_xml = '&lt;AddressValidateRequest USERID="xxxxxxx"&gt;
&lt;Address ID="0"&gt;
    &lt;Address1&gt;&lt;/Address1&gt;
    &lt;Address2&gt;6406 Ivy Lane&lt;/Address2&gt;&lt;City&gt;Greenbelt&lt;/City&gt;
&lt;State&gt;MD&lt;/State&gt;
&lt;Zip5&gt;&lt;/Zip5&gt;
&lt;Zip4&gt;&lt;/Zip4&gt;
&lt;/Address&gt;
&lt;/AddressValidateRequest&gt;';

$url = "http://production.shippingapis.com/ShippingAPITest.dll?API=Verify";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_POSTFIELDS,
                "xmlRequest=" . $input_xml);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
    $data = curl_exec($ch);
    curl_close($ch);

    //convert the XML result into array
    $array_data = json_decode(json_encode(simplexml_load_string($data)), true);

    print_r('&lt;pre&gt;');
    print_r($array_data);
    print_r('&lt;/pre&gt;');
</code></pre>

<p>I am hoping someone can help with what I am doing wrong...</p>