php nusoap 类,关于php:NuSOAP:如何更改请求的内容类型?

使用.NET WCF Web服务时,我得到以下响应(错误):

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

如何更改内容类型? 我在NuSOAP论坛/文档中找不到它,否则我可能会忽略某些东西。

我知道这是一篇旧文章,但是我跑到该页面寻找答案。

application/soap+xml是使用SOAP 1.2时传递的内容类型,

text/xml与SOAP 1.1一起使用,

这样的事情应该可以解决问题,

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

您可以使用以下Web服务指定NuSOAP流的编码:

$client = new nusoap_client($params);

$client->soap_defencoding = 'UTF-8';

哇,那很容易。 谢谢!

看起来NuSOAP库中略有遗漏……它假定内容标头必须为" text / xml",因此,如果您的客户端尝试连接到输出application / soap + xml标头的服务,则最终会出现如下错误:

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

为了测试这一点,您可能会受益于以下用于登录SOAP服务的小功能模式。记住,打印出客户对象!您可能实际上没有得到要看的结果!

require_once('path/to/downloaded/libraries/nusoap.php');

var $endpoint = 'https://somedomain.com/path/to/soap/server/Login';

var $client; // the soapclient object

function SOAP_Login()

{

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

$err = $this->client->getError();

if ($err)

{

// Display the error

echo '

SOAP Constructor error: ' . $err . '

exit;

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

}

当我打印$ result时,什么也没得到,但是当我打印$ client对象时,我看到有错误。

我实现的小技巧是在7500行附近的nusoap.php文件中。查找以下if语句:

if (!strstr($headers['content-type'], 'text/xml')) {

$this->setError('Response not of type text/xml: ' . $headers['content-type']);

return false;

}

并将其更改为:

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;

}

这一切都是为了让NuSOAP处理发出" application / soap + xml"标头(这是有效的xml标头)的响应。

这为我工作:

$ client =新的nusoap_client($ params);

$ client-> soap_defencoding ='UTF-8';

标记为正确的答案不适用于NUSOAP,因此不是适当的答案。

我也坚持这一点。

秘密在web.config中

将wsHttpBinding更改为basicHttpBinding

像这样:

希望有帮助!

/埃里克

我无法将其更改为basicHttpBinding,因为我们的证书需要wsHttpBinding。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值