NuSOAP:如何更改请求的内容类型?

发布于 2024-07-22 20:48:05 字数 254 浏览 8 评论 0原文

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

不支持的 HTTP 响应状态 415 无法处理消息,因为内容类型为“text/xml;” 字符集=UTF-8' 不是预期的类型“application/soap+xml;” 字符集=utf-8'。

如何更改内容类型? 我在 NuSOAP 论坛/文档中找不到它,或者我可能忽略了一些东西......

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

小矜持 2024-07-29 20:48:06

这对我有用:

$client = new nusoap_client($params);

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

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

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.

北方的韩爷 2024-07-29 20:48:05

我知道这是一篇旧帖子,但我跑到此页面寻找答案。

application/soap+xml 是使用 SOAP 1.2 时传递的内容类型,
text/xml 与 SOAP 1.1 一起使用,

类似这样的东西应该可以解决问题,

$client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_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));
时光清浅 2024-07-29 20:48:05

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

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

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

$client = new nusoap_client($params);
$client->soap_defencoding = 'UTF-8';
夜司空 2024-07-29 20:48:05

看起来 NuSOAP 库中有一个轻微的遗漏...它假设内容标头必须是“text/xml”,因此如果您的客户端尝试连接到输出 application/soap+xml 标头的服务,那么您'最终会出现如下错误:

响应不是 text/xml 类型:application/soap+xml; 字符集=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 '<p><b>SOAP Constructor error: ' . $err . '</b></p>';
        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 对象时,我可以看到有错误。

我实现的小技巧是在 nusoap.php 文件中,大约第 7500 行。查找这个 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 标头)。

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!

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 '<p><b>SOAP Constructor error: ' . $err . '</b></p>';
        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
}

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

迷爱 2024-07-29 20:48:05

我也被困在这个问题上。

秘密就在 web.config 中
将 wsHttpBinding 更改为 basicHttpBinding

像这样:

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

希望有帮助!
/埃里克

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文