donglun7151 2017-03-22 18:35
浏览 144

PHP SOAP调用内容类型

I'm attempting to connect with a WS via Soap and struggling with a content type error when I call the method: content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'

Below is my code, reducing number of params and hiding url, user and password.

The error happens when I call the ClientRegist() function. I'm convinced I have to pass $params in a different way, but can't find an example anywhere.

$url = 'http://---';

$ctx_opts = array(
  'http' => array(
    'header' => 'Content-Type: application/soap+xml'
  ),
  'username' => '---',
  'password' => '---',
  'trace' => true,
  'exceptions' => true
);

$ctx = stream_context_create($ctx_opts);

$client = new SoapClient($url, array('stream_context' => $ctx));

$params = array(
  'Cardnumber' => $number,
  'Name' => $name
);

try {
  $client = new SoapClient($url, array('trace' => $trace, 'exceptions' => $exceptions));
  $response = $client->ClientRegist($params);
}

catch (Exception $e) {
  echo "Error!<br>";
  echo $e -> getMessage ().'<br>';
  echo 'Last response: '. $client->__getLastResponse();
}

var_dump($response);
  • 写回答

1条回答 默认 最新

  • douzhunlan5930 2017-07-18 13:18
    关注

    Try SOAP version 1.2. Its default Content-Type is application/soap+xml

    <?php
    
    // ...
    
    $client = new SoapClient(
        $url,
        array(
            'soap_version' => SOAP_1_2, // !!!!!!!
            'stream_context' => $ctx
        )
    );
    
    评论

报告相同问题?