title: Sending XML fails
body: <p>I'm trying to send XML to a remote site. I originally coded it using curl. That failed (no response) and the rep for the company said it was because I was using curl. So I changed the code to not use it but it fails with </p>
  
  <blockquote>
    <p>file_get_contents(<a href="https://testws.atdconnect.com/ws/3_4/locations.wsdl/" rel="nofollow noreferrer">https://testws.atdconnect.com/ws/3_4/locations.wsdl/</a>) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error</p>
  </blockquote>
  
  <p>The code I am using is shown below. The first call tries to send with curl while the second doesn't. Can someone point out where I am going wrong, please?</p>
  
  <pre><code>    $client_id = "the id";
      $username = "the user";
      $password = "the pass";
      $url = "https://testws.atdconnect.com/ws/3_4/locations.wsdl/";
  
      echo GetDistributionCenter($url, $client_id, $username, $password);
      echo GetDistributionCenter($url, $client_id, $username, $password, true);
  
      function GetDistributionCenter($url, $client_id, $username, $password, $send_array = false) {
         $xml_str = '
          &lt;?xml version="1.0" encoding="UTF-8"?&gt;
          &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:loc="http://api.atdconnect.com/atd/3_4/locations"&gt;
           &lt;soapenv:Header&gt;
             &lt;wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;
                &lt;wsse:UsernameToken atd:clientId="' . $client_id . '" xmlns:atd="http://api.atdconnect.com/atd"&gt;
                &lt;wsse:Username&gt;' . $username . '&lt;/wsse:Username&gt; 
                &lt;wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"&gt;' . $password . '&lt;/wsse:Password&gt;
             &lt;/wsse:UsernameToken&gt;
             &lt;/wsse:Security&gt;
           &lt;/soapenv:Header&gt;
           &lt;soapenv:Body&gt;
             &lt;loc:getDistributionCenterRequest&gt;
                &lt;loc:servicingDC&gt;070&lt;/loc:servicingDC&gt;
             &lt;/loc:getDistributionCenterRequest&gt;
           &lt;/soapenv:Body&gt;
          &lt;/soapenv:Envelope&gt;';
  
         if ($send_array) {
            $xml_str = array($xml_str);
            $xml_str = http_build_query($xml_str);
            return  SendPostRequest($url, $xml_str);
         }   
  
         return SendXMLCommand($url, $xml_str);
      } 
  
      function SendPostRequest($url, $postdata) {
         $opts = array('http' =&gt;
             array(
                 'method'  =&gt; 'POST',
                 'header'  =&gt; 'Content-type: application/x-www-form-urlencoded',
                 'Content-Length: ' . strlen($postdata) . "\r\n",
                 'content' =&gt; $postdata
             )
         );
         $context  = stream_context_create($opts);
         return file_get_contents($url, false, $context);
      }
  
      function SendXMLCommand($url, $parsed_data) {
          $ch = curl_init();
          $timeout = 5; 
          curl_setopt ($ch, CURLOPT_URL, $url);
          curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'POST');
          curl_setopt ($ch, CURLOPT_POSTFIELDS, $parsed_data);
          curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, true);  
          curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);                                 
          curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
          curl_setopt ($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","SOAPAction: \"/soap/action/query\"", "Content-length: ".strlen($data))); 
          $result = curl_exec($ch);
  
          if (curl_error($ch)) {
              $result = 'Curl error: ' . curl_error($ch);
          }
  
          curl_close($ch);
  
          return $result;
      }
  </code></pre>