[英]How can I set the HTTP header “Access-Control-Allow-Origin” for HTTP responses from a thttpd web server
I have a thttpd ( http://acme.com/software/thttpd/ ) web-server on which I have images (svg) and JSON files.我有一个 thttpd ( http://acme.com/software/thttpd/ ) 网络服务器,上面有图像 (svg) 和 JSON 文件。
I'm developping a small web page that needs to retrieves these resources from my web-server but I always get the following error :我正在开发一个需要从我的网络服务器检索这些资源的小网页,但我总是收到以下错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
I know that I have to set the Access-Control-Allow-Origin header on the server side to accept requests from any origin like in a .htaccess file on an Apache server :我知道我必须在服务器端设置 Access-Control-Allow-Origin 标头以接受来自任何来源的请求,例如 Apache 服务器上的 .htaccess 文件:
Header set Access-Control-Allow-Origin *
But I really can't figure out how to do that on a thttpd server.但我真的不知道如何在 thttpd 服务器上做到这一点。 All the documentation and related topics I've read so far are for Apache, NGINX, IIS6, ...
到目前为止,我读过的所有文档和相关主题都适用于 Apache、NGINX、IIS6……
I have all the needed rights to modify the configuration files on the web-server (I have root access).我拥有修改网络服务器上的配置文件所需的所有权限(我有 root 访问权限)。
Note that I also tried to use "jsonp" as data type in my HTTP Request, in my Javascript code, but I get the following error while trying to retrieve my JSON file.请注意,我还尝试在我的 HTTP 请求中的 Javascript 代码中使用“jsonp”作为数据类型,但是在尝试检索我的 JSON 文件时出现以下错误。
Uncaught SyntaxError: Unexpected token :
Anyway I also need to get images in SVG format so I would like to avoid using "jsonp" as data type.无论如何,我还需要以 SVG 格式获取图像,因此我想避免使用“jsonp”作为数据类型。
Here's my javascript code :这是我的 javascript 代码:
31 $.ajax({
33 url: "http://ip_address/file.json",
34 dataType: "jsonp",
35 crossDomain: true,
36 data: {
37 format: "json"
38 },
39 success: function(data) {
40 var json = $.parseJSON(data);
41 alert(data);
42 }
43 });
any help would be really appreciated !任何帮助将不胜感激!
Thanks谢谢
In libhttpd.c you can update the response string to include在 libhttpd.c 中,您可以更新响应字符串以包含
Change改变
"%.20s %d %s\\015\\012Server: %s\\015\\012Content-Type: %s\\015\\012Date: %s\\015\\012Last-Modified: %s\\015\\012Accept-Ranges: bytes\\015\\012Connection: close\\015\\012"
To至
"%.20s %d %s\\015\\012Server: %s\\015\\012Content-Type: %s\\015\\012Date: %s\\015\\012Last-Modified: %s\\015\\012Accept-Ranges: bytes\\015\\012Access-Control-Allow-Origin: *\\015\\012Connection: close\\015\\012"
https://github.com/uoaerg/thttpd/blob/master/libhttpd.c#L652https://github.com/uoaerg/thttpd/blob/master/libhttpd.c#L652
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.