Fetch API无法加载http:// localhost:3000

时间:2017-02-22 14:41:28

标签: google-chrome http

运行Chrome 56并在我的控制台中记录以下消息,执行跨源fetch():

Fetch API cannot load http://localhost:8080/transaction. 
No 'Access-Control-Allow-Origin' :3000/#/1 header is present on the requested resource. 
Origin 'http://localhost:3000' is therefore not allowed access. 
If an opaque response serves your needs, set the request's mode to 
'no-cors' to fetch the resource with CORS disabled.

Chrome的网络标题标签显示标题已存在,Chrome会执行跨源PUT请求,就像飞行前的工作一样。以下是Chrome对OPTIONS请求和响应的说法:

General
    Request URL:http://localhost:8080/transaction
    Request Method:OPTIONS
    Status Code:200 OK
    Remote Address:[::1]:8080
Response Headers
    Access-Control-Allow-Headers:Content-Type
    Access-Control-Allow-Methods:PUT
    Access-Control-Allow-Origin:http://localhost:3000
    Connection:keep-alive
    Content-Length:0
    Date:Wed, 22 Feb 2017 14:28:23 GMT
Request Headers
    Accept:*/*
    Accept-Encoding:gzip, deflate, sdch, br
    Accept-Language:en-US,en;q=0.8
    Access-Control-Request-Headers:
    Access-Control-Request-Method:PUT
    Cache-Control:no-cache
    Connection:keep-alive
    DNT:1
    Host:localhost:8080
    Origin:http://localhost:3000
    Pragma:no-cache
    Referer:http://localhost:3000/
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36

有人知道我收到此消息的原因吗?

1 个答案:

答案 0 :(得分:0)

好的,可以回答我自己的问题。问题是对PUT的响应没有Access-Control-Allow-Origin标头。