【问题标题】:PHP SOAP call content typePHP SOAP 调用内容类型
【发布时间】:2017-03-22 18:35:36
【问题描述】:

我正在尝试通过 Soap 与 WS 连接,并在调用该方法时遇到内容类型错误:content type 'text/xml; charset=utf-8' 不是预期的类型 'application/soap+xml; charset=utf-8'

以下是我的代码,减少了参数数量并隐藏了 url、用户和密码。

当我调用 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);

【问题讨论】:

    标签: php web-services soap header content-type


    【解决方案1】:

    试试 SOAP 版本 1.2。它的默认 Content-Type 是 application/soap+xml

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

    【讨论】:

      猜你喜欢
      • 2017-11-08
      • 1970-01-01
      • 2013-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-27
      • 1970-01-01
      相关资源
      最近更新 更多