我用gSOAP開發webservice。其中一種方法返回json輸出。但是,瀏覽器需要傳遞標頭(Access-Control-Allow-Origin)。 gSOAP在發送數據之前是否支持傳遞標題?gSOAP指定訪問控制允許來源
UPD:發現
解決方案。只需添加一些代碼來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*/
}
我正在使用GET方法。當我嘗試以發佈方式發送標題時,它們會作爲返回文檔的一部分出現。 – vladf