首页 文章

PHP SOAP调用内容类型

提问于
浏览
0

我正在尝试通过Soap连接WS并在调用方法时遇到内容类型错误: content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'

下面是我的代码,减少了参数和隐藏网址,用户和密码的数量 .

当我调用ClientRegist()函数时发生错误 . 我确信我必须以不同的方式传递$ params,但无法在任何地方找到一个例子 .

$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 回答

  • 2

    尝试SOAP 1.2版 . 它的默认Content-Type是application / soap xml

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

相关问题