在404错误的情况下,gsoap更改响应内容类型

时间:2014-12-24 09:08:44

标签: http-post gsoap

我使用gsoap httppost插件来实现接受发布请求的服务器。

如果出现错误,我将返回404错误,但内容类型始终为text/xml,但我要求内容类型为text/html

下面的

是代码段

int wildcard_handler(struct soap* soap)
{
    stringstream ss;
    ss << "In wild card handler content_type" << soap->http_content;
    LOGDEBUG(ss.str());

    soap->http_content = "text/html";
    soap_send_empty_response(soap, 404);
    return SOAP_OK;

}

但在浏览器上我收到text / xml&amp;错误404。

1 个答案:

答案 0 :(得分:1)

stdsoap2.cpp开始,为了返回text/html答案,您应该使用:

int wildcard_handler(struct soap* soap)
{
    soap_response(soap, SOAP_HTML);
    soap_send(soap, "<HTML>...</HTML>");
    soap_end_send(soap);
    soap_closesock(soap);
    return SOAP_OK;
}

这将允许您发送HTML答案,但不会发送错误404.

为了发送404和text/html内容是可能的,但它更复杂,因为它需要覆盖soap-&gt; fresponse处理程序来传播http错误代码和SOAP_HTML标志。