title: How to set SoapClient HTTP content type to application/soap+xml
body: <p>I need to change the content type from "text/xml; charset=utf-8" to "application/soap+xml; charset=utf-8". </p>
  
  <p>I'm sending a request from PHP to another server (Oracle server) using SoapClient class that exist by default in PHP. I'm using PHP v7.0.10.</p>
  
  <p>As per SoapClient documentation I should just set the soap_version inside the options array to SOAP_1_2 and it will change the content type but it doesn't do that.</p>
  
  <p>SOAP Request</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pub="http://xmlns.oracle.com/oxp/service/PublicReportService"&gt;
      &lt;soap:Header/&gt;
      &lt;soap:Body&gt;
          &lt;pub:runReport&gt;
              &lt;pub:reportRequest&gt;
                  &lt;pub:reportAbsolutePath&gt;/Human Capital Management/Workforce Management/Human Resources Dashboard/Fusion User Information.xdo&lt;/pub:reportAbsolutePath&gt;
                  &lt;pub:sizeOfDataChunkDownload&gt;-1&lt;/pub:sizeOfDataChunkDownload&gt;
              &lt;/pub:reportRequest&gt;
          &lt;/pub:runReport&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>PHP Code</p>
  
  <pre><code>$WSDL = "https://example.com/xmlpserver/services/ExternalReportWSSService?WSDL";
  
      $soap_options = array(
          'uri' =&gt; 'http://www.w3.org/2003/05/soap-envelope',
          'style' =&gt; SOAP_RPC,
          'use' =&gt; SOAP_ENCODED,
          'soap_version' =&gt; SOAP_1_2,
          'cache_wsdl' =&gt; WSDL_CACHE_NONE,
          'connection_timeout' =&gt; 30,
          'trace' =&gt; true,
          'encoding' =&gt; 'UTF-8',
          // 'exceptions' =&gt; true,
          'location' =&gt; $WSDL,
          'login' =&gt; '---',
          'password' =&gt; '---'
      );
  
      try {
          $soap_client = new SoapClient(NULL, $soap_options);
          $result = $soap_client-&gt;__doRequest($soap_request, $WSDL, "run", NULL);
          $clean_xml = str_ireplace(['SOAP-ENV:', 'SOAP:', 'env:'], '', $result);
          $xml = simplexml_load_string($clean_xml);
          var_dump($xml);
      } catch (Exception $e) {
          echo $e;
      }
  </code></pre>
  
  <p>Last request header shows</p>
  
  <pre><code>POST /xmlpserver/services/ExternalReportWSSService?WSDL HTTP/1.1
  Host: example.com
  Connection: Keep-Alive
  User-Agent: PHP-SOAP/7.0.10
  Content-Type: text/xml; charset=utf-8
  SOAPAction: ""
  Content-Length: 510
  Authorization: Basic ---
  </code></pre>
  
  <p>I've tried to set the content type by so many ways and every one of them failed</p>
  
  <p><strong>Update &amp; Solution</strong></p>
  
  <pre><code>&lt;?php
  
      $soap_request = &lt;&lt;&lt;XML
  &lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pub="http://xmlns.oracle.com/oxp/service/PublicReportService"&gt;
      &lt;soap:Header/&gt;
      &lt;soap:Body&gt;
          &lt;pub:runReport&gt;
              &lt;pub:reportRequest&gt;
                  &lt;pub:reportAbsolutePath&gt;/Human Capital Management/Workforce Management/Human Resources Dashboard/Fusion User Information.xdo&lt;/pub:reportAbsolutePath&gt;
                  &lt;pub:sizeOfDataChunkDownload&gt;-1&lt;/pub:sizeOfDataChunkDownload&gt;
              &lt;/pub:reportRequest&gt;
          &lt;/pub:runReport&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  XML;
  
  $WSDL = "https://example.com/xmlpserver/services/ExternalReportWSSService?WSDL";
      $user = "---";
      $password = "---";
  $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_HEADER,         false);
      curl_setopt($ch, CURLOPT_URL,            $WSDL);
      curl_setopt($ch, CURLOPT_FAILONERROR,    true); 
      curl_setopt($ch, CURLOPT_HTTPHEADER,     Array(
          'Content-Type: application/soap+xml; charset=utf-8', 
          'SOAPAction: "run"',
          'Accept: text/xml',
          'Cache-Control: no-cache',
          'Pragma: no-cache',
          'Content-length: '. strlen($soap_request),
          'User-Agent: PHP-SOAP/7.0.10'
      ));
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($ch, CURLOPT_USERPWD,        $user.":".$password);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
      curl_setopt($ch, CURLOPT_TIMEOUT,        30);
      curl_setopt($ch, CURLOPT_POSTFIELDS,     $soap_request);
      $response = curl_exec($ch); 
      if (empty($response)) { 
          throw new SoapFault('CURL error: '.curl_error($ch), curl_errno($ch)); 
      } 
      curl_close($ch);
      var_dump($response);
  ?&gt;
  </code></pre>