英文:
XMLHttpRequest cannot load http://localhost:9090/receive. No 'Access-Control-Allow-Origin' header is present on the requested resource
问题
我正在通过nginx服务器打开一个HTML文件,然后该HTML文件通过dropzone将"POST"请求传递给nginx服务器,然后nginx服务器通过proxy_pass将请求转发给我的Go服务器。我的Go服务器接受该请求。
但是当我尝试使用我的HTML文件并在dropzone中放置一些内容时,我收到以下错误信息:
XMLHttpRequest无法加载http://localhost:9090/receive。所请求的资源上没有"Access-Control-Allow-Origin"头。因此,来自"http://localhost:9009"的源不被允许访问。
请帮助我解决这个问题。
英文:
I am opening a html file through nginx server and then the html file passes the "POST" request from the dropzone to the nginx server which then proxy_pass to my go server.This go server then accepts the request.
But when i try to use my html file and drop something in the dropzone i get the error :
XMLHttpRequest cannot load http://localhost:9090/receive. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9009' is therefore not allowed access.
PLease help me out.
答案1
得分: 1
在你上面的错误中,你从http://localhost:9009
加载页面,请求到http://localhost:9090/
。根据同源策略的描述(参见https://www.rfc-editor.org/rfc/rfc6454#section-5),这两者是不同的源。
源必须匹配:
- 协议
- 主机
- 端口
对于你来说,协议和主机是相同的,但是端口不同。因此,你需要添加CORS头,以允许调用者在http://localhost:9090
上调用你的服务器。
英文:
In your error above you have the page loading from http://localhost:9009
requesting to http://localhost:9090/
. These are different origins according to the Same Origin description here: https://www.rfc-editor.org/rfc/rfc6454#section-5
The origins must match:
- scheme
- host
- port
For you the the scheme and host are the same, but the ports are different. Thus you will need to add the CORS headers to allow the caller to call your server on http://localhost:9090
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论