NuSOAP: how to change content-type of request?

When consuming a .NET WCF webservice I get the following response (error):

Unsupported HTTP response status 415
Cannot process the message because the content type ‘text/xml; charset=UTF-8’
was not the expected type ‘application/soap+xml; charset=utf-8’.

How do I change the content type? I can’t find it in the NuSOAP forums/docs, or I might be overlooking something….

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

i know this is an old post, but i ran in to this page looking for an answer.

application/soap+xml is the content-type passed when using SOAP 1.2,
text/xml is used with SOAP 1.1,

something like this should do the trick,

$client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_1));

Solution 2

You can specify the encoding of NuSOAP streams with the webservices like that :

$client = new nusoap_client($params);
$client->soap_defencoding = 'UTF-8';

Solution 3

It looks like there’s a slight omission in the NuSOAP library… it assumes that the content headers MUST be “text/xml”, so if your client is attempting to connect to a service that outputs application/soap+xml headers, you’ll end up with errors like:

Response not of type text/xml: application/soap+xml; charset=utf-8

To test this, you may benefit from the following little function pattern, which I used to login to a SOAP service. Remember, print out the client object! You may not actually get a result to look at!

var $endpoint = '';
var $client; // the soapclient object

function SOAP_Login()
    $this->client = new soapclient($this->endpoint);

    $err = $this->client->getError();
    if ($err) 
        // Display the error
        echo '<p><b>SOAP Constructor error: ' . $err . '</b></p>';
        // At this point, you know the call that follows will fail

    $params = array( 
        'some' => 'thing.. depends on what the WSDL expects'

    $result = $this->client->call('someFunction', $params);     

    print_r($result);  // Without the fix, this prints nothing (i.e. false) !!!

    print_r($this->client); // Instead, look at the state of the client object, specifically error_str and debug_str

When I printed my $result, I got nothing, but when I printed out the $client object, I could see that there were errors.

The little hack I implemented was in the nusoap.php file, around line 7500. Look for this if-statement:

if (!strstr($headers['content-type'], 'text/xml')) {
    $this->setError('Response not of type text/xml: ' . $headers['content-type']);
    return false;

And change it to this:

if (!strstr($headers['content-type'], 'text/xml') && !strstr($headers['content-type'], 'application/soap+xml') ) {
    $this->setError('Response not of type text/xml: ' . $headers['content-type']);
    return false;

All this does is it lets NuSOAP handle responses that issue an “application/soap+xml” header (which is a valid xml header).

Solution 4

I was stuck on this as well.

The secret is in the web.config
Change wsHttpBinding to basicHttpBinding

Like so:

<endpoint address="" binding="basicHttpBinding" contract="YourProject.View.Whatever.IYourService">

Hope that helps!

Solution 5

This worked for me:

$client = new nusoap_client($params);

$client->soap_defencoding = ‘UTF-8’;

The answer that is ticked as correct is not for NUSOAP therefore not the appropriate answer.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply