简体   繁体   English

如何为来自 thttpd Web 服务器的 HTTP 响应设置 HTTP 标头“Access-Control-Allow-Origin”

[英]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.

相关问题 我如何在 Node.JS Http 服务器中允许“访问控制允许来源”? - How do i allow 'Access-Control-Allow-Origin' in Node.JS Http Server? 跨域 XMLHttpRequest、Access-Control-Allow-Origin 标头和 $_SERVER['HTTP_ORIGIN'] - Cross-domain XMLHttpRequest, Access-Control-Allow-Origin header and $_SERVER['HTTP_ORIGIN'] 角$ http.post并且没有'Access-Control-Allow-Origin'标头 - Angular $http.post and No 'Access-Control-Allow-Origin' header Web API的$ http角向给出XMLHttpRequest错误-请求的资源上没有'Access-Control-Allow-Origin'标头 - Angular $http to Web Api gives error of XMLHttpRequest -No 'Access-Control-Allow-Origin' header is present on the requested resource 为什么如果此API提供“ No Access-Control-Allow-Origin标头”,为什么可以通过地址栏或http://www.hurl.it访问它 - Why if this API gives the “No Access-Control-Allow-Origin header”, can I access it through the address bar or http://www.hurl.it http请求中的Access-Control-Allow-Origin - Access-Control-Allow-Origin in http request 用于 http 和 https 的访问控制允许来源 - Access-Control-Allow-Origin for http & https 如何为XDomain设置标头Access-Control-Allow-Origin - How to set header Access-Control-Allow-Origin for XDomain NestJS - 如何为响应设置“Access-Control-Allow-Origin”标头 - NestJS - How to set 'Access-Control-Allow-Origin' Header for Response 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问来源“ http:// localhost” - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM