谷歌地图地理编码API中的CORS错误
CORS error in Google Maps Geocoding API
我正面临一个相当突然的谷歌地图地理编码问题。这一切都工作得很好,直到昨天,但从那以后,我一直得到一个CORS错误对他们的地理编码API的任何请求。
我的请求:
https://maps.googleapis.com/maps/api/geocode/json?latlng=18.92187618976372,72.82581567764282&key=<API_KEY>
我的请求头:
Provisional headers are shown
Accept:application/json, text/plain, */*
Origin:http://domain
Referer:http://domain/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36
X-FirePHP-Version:0.0.6
响应标头:
access-control-allow-origin:*
alternate-protocol:443:quic,p=1
cache-control:public, max-age=86400
content-encoding:gzip
content-length:1279
content-type:application/json; charset=UTF-8
date:Thu, 23 Jul 2015 09:50:49 GMT
expires:Fri, 24 Jul 2015 09:50:49 GMT
server:mafe
status:200
vary:Accept-Language
x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=block
错误信息:
XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/geocode/json?latlng=18.92187618976372,72.82581567764282&key=<API_KEY>. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://domain' is therefore not allowed access.
将标题设置为null对我来说很有效。
let url= `https://maps.googleapis.com/maps/api/geocode/json?latlng=${payload.lat},${payload.lng}&key=${process.env.NEXT_PUBLIC_GOOGLE_MAP}`;
const res = await axios.get(url,{headers:null});
我的系统是这样设置的,我的前端是从我的逻辑服务器的跨域服务。为此,我将withCredentials
标记设置为true
。由于Maps的API使用*
通配符,withCredentials
给出了一个错误。
为了解决这个问题,我为Maps调用使用了一个单独的XHR方法,其中将标志设置为false。
相关文章:
- AngularJS应用程序中的CORS错误
- XDomainRequest (CORS) for XML 导致 IE8 / IE9 中的“访问被拒绝”错误
- CORS AJAX 请求 Chrome 中的本地 WSGI 服务器时延迟过长
- 节点中的 CORS 问题.js失败
- 简单请求中的 Cors 错误:请求标头字段 预检响应中的访问控制-允许-标头不允许授权
- 快速 JS 中的 CORS 问题
- 全局配置$http以在angularJS中使用CORS(所有请求的固定域)
- 允许AnguarJS和PHP中的CORS
- 其中'azure移动服务中的CORS设置已经消失了
- 如何在谷歌驱动器上托管的文件夹中启用CORS
- 没有在窗口上发送表单数据就触发CORS请求.IE9中的onbeforeunload事件
- Javascript中的CORS实现
- 处理Node.js中的CORS
- 在浏览器中删除状态码>= 400的CORS标头
- 在ExtJS表单中的CORS问题
- 谷歌地图地理编码API中的CORS错误
- 如何解决google API中的CORS问题
- 无法绕过angularjs种子应用程序中的CORS
- JS中的CORS错误(XMLRequest)
- Jquery Ajax Post中的CORS问题