我使用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。
答案 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标志。