Php soap set content-type header

@@ -74,13 +74,21 @@ public function doRequest($request, $location, $action, $version, $one_way = 0,
$vcrRequest = new Request('POST', $location);
$encoding = 'utf-8'; if (array_key_exists('encoding', $options)) { $encoding = $options['encoding']; }
if ($version === SOAP_1_1) { $vcrRequest->setHeader('Content-Type', 'text/xml; charset=utf-8;'); $vcrRequest->setHeader( 'Content-Type', sprintf('text/xml; charset=%s;', $encoding) ); $vcrRequest->setHeader('SOAPAction', $action); } else { // >= SOAP_1_2 $vcrRequest->setHeader( 'Content-Type', sprintf('application/soap+xml; charset=utf-8; action="%s"', $action) sprintf('application/soap+xml; charset=%s; action="%s"', $encoding, $action) ); }

I need to change the content type from "text/xml; charset=utf-8" to "application/soap+xml; charset=utf-8".

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.

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.

SOAP Request

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pub="http://xmlns.oracle.com/oxp/service/PublicReportService">
    <soap:Header/>
    <soap:Body>
        <pub:runReport>
            <pub:reportRequest>
                <pub:reportAbsolutePath>/Human Capital Management/Workforce Management/Human Resources Dashboard/Fusion User Information.xdo</pub:reportAbsolutePath>
                <pub:sizeOfDataChunkDownload>-1</pub:sizeOfDataChunkDownload>
            </pub:reportRequest>
        </pub:runReport>
    </soap:Body>
</soap:Envelope>

PHP Code

$WSDL = "https://example.com/xmlpserver/services/ExternalReportWSSService?WSDL";

    $soap_options = array(
        'uri' => 'http://www.w3.org/2003/05/soap-envelope',
        'style' => SOAP_RPC,
        'use' => SOAP_ENCODED,
        'soap_version' => SOAP_1_2,
        'cache_wsdl' => WSDL_CACHE_NONE,
        'connection_timeout' => 30,
        'trace' => true,
        'encoding' => 'UTF-8',
        // 'exceptions' => true,
        'location' => $WSDL,
        'login' => '---',
        'password' => '---'
    );

    try {
        $soap_client = new SoapClient(NULL, $soap_options);
        $result = $soap_client->__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;
    }

Last request header shows

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 ---

I've tried to set the content type by so many ways and every one of them failed

Update & Solution

<?php

    $soap_request = <<<XML
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pub="http://xmlns.oracle.com/oxp/service/PublicReportService">
    <soap:Header/>
    <soap:Body>
        <pub:runReport>
            <pub:reportRequest>
                <pub:reportAbsolutePath>/Human Capital Management/Workforce Management/Human Resources Dashboard/Fusion User Information.xdo</pub:reportAbsolutePath>
                <pub:sizeOfDataChunkDownload>-1</pub:sizeOfDataChunkDownload>
            </pub:reportRequest>
        </pub:runReport>
    </soap:Body>
</soap:Envelope>
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);
?>

How do you set a SOAP request header?

Adding SOAP headers to a SOAP request message.
Create a private variable: ... .
Select the service task or web service integration component and click the Variables tab above the diagram area..
Create the private variable that you will later map to the SOAP header of the request message..

What is header in SOAP message?

The SOAP <Header> is an optional element in a SOAP message. It is used to pass application-related information that is to be processed by SOAP nodes along the message path. The immediate child elements of the <Header> element are called header blocks.

How to send XML data in SOAP request PHP?

To make SOAP requests to the SOAP API endpoint, use the "Content-Type: application/soap+xml" request header, which tells the server that the request body contains a SOAP envelope. The server informs the client that it has returned a SOAP envelope with a "Content-Type: application/soap+xml" response header.

What does SOAP header contain?

A SOAP header contains application-specific context information (for example, security or encryption information) that is associated with the SOAP request or response message. There is only one SOAP header section in a SOAP request.