gpt4 book ai didi

c++ - gSOAP 指定访问控制允许来源

转载 作者:太空宇宙 更新时间:2023-11-04 13:26:56 25 4
gpt4 key购买 nike

我已经使用 gSOAP 开发了网络服务。其中一种方法返回 json 输出。但是浏览器需要传递 header (Access-Control-Allow-Origin)。 gSOAP 是否支持在发送数据之前传递 header ?

更新:

已找到解决方案。只需在 http_response 函数中添加一些代码:

static int
http_response(struct soap *soap, int status, size_t count)
{
/* some code goes here*/
if ((err = soap->fposthdr(soap, "Access-Control-Allow-Origin", "*")))
return err;
if ((err = soap->fposthdr(soap, "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, CONNECT")))
return err;
if ((err = soap->fposthdr(soap, "Access-Control-Allow-Headers", "X-Requested-With, Content-Type")))
return err;
if ((err = soap->fposthdr(soap, "Access-Control-Allow-Credentials", "true")))
return err;
/* some code goes here*/
}

最佳答案

我从来没有找到任何方法在我自己的代码中做到这一点——但我能够通过修改 stdsoap2.cpp 来做到这一点,这看起来没问题,因为无论如何你都需要将它编译到你的代码中。我所做的是在 http_post 函数结束之前添加 ClientCertSubjectDN header :

/******************************************************************************/
#ifndef WITH_NOHTTP
#ifndef PALM_1
static int
http_post(struct soap *soap, const char *endpoint, const char *host, int port, const char *path, const char *action, size_t count)
{ register const char *s;
register int err;
... the code of the function (except the return at the end) ...

/* add more headers */
if ((err = soap->fposthdr(soap, "ClientCertSubjectDN", "CN=IVR Production")))
return err;

return soap->fposthdr(soap, NULL, NULL);
}
#endif
#endif

关于c++ - gSOAP 指定访问控制允许来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33001662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com