axios 补丁在 Chrome 中不起作用 [英] axios patch not working in chrome
问题描述
我正在尝试使用 React axios 更新 drupal 站点上的一些文章.GET 和 POST 请求有效,但我无法让 PATCH 工作.通过 Postman 发送 PATCH 请求工作正常.使用 axios 时出现以下错误:
I'm trying to update some articles on a drupal site using React axios. GET and POST requests work, but I can't get PATCH to work. Sending the PATCH request through Postman works just fine. I get the following error using axios:
Access-Control-Allow-Methods 中不允许方法 PATCH飞行前响应.
Method PATCH is not allowed by Access-Control-Allow-Methods in preflight response.
我做错了什么?
这是我的代码:
editState(nid, value){
let node = {
"type":[{"target_id":"article","target_type":"node_type"}],
"body":[{"value": value}]
}
let config = {
headers: { 'Content-Type': 'application/json' }
}
axios.patch('http://localhost:8888/d8restapi/node/' + nid + '?_format=json',node,config)
.then((success) => {
console.log(success);
}).catch((error) => {
console.log(error);
});
}
这是我的 OPTIONS 请求标头:
Here are my OPTIONS request Headers:
- 请求 URL:http://localhost:8888/d8restapi/node/16?_format=json
- 请求方法:OPTIONS
- 状态代码:200 OK
- 远程地址:[::1]:8888
- 推荐人政策:降级时禁止推荐人
- 响应头
- 查看源代码
- 允许:获取、发布、删除、修补
- 缓存控制:必须重新验证、无缓存、私有
- 连接:保持活动
- 内容语言:en
- 内容长度:0
- 内容类型:应用程序/json
- 日期:2017 年 11 月 3 日星期五 21:08:24 GMT
- 到期:星期日,1978 年 11 月 19 日 05:00:00 GMT
- Keep-Alive:timeout=5, max=98
- 服务器:Apache/2.2.31 (Unix) mod_wsgi/3.5 Python/2.7.12 PHP/7.0.10
- mod_ssl/2.2.31 OpenSSL/1.0.2h DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.9
- Perl/v5.24.0
- X-Content-Type-Options:nosniff
- X-Content-Type-Options:nosniff
- X-Frame-Options:SAMEORIGIN
- X-Generator:Drupal 8 (https://www.drupal.org)
- X-Powered-By:PHP/7.0.10
- X-UA-Compatible:IE=edge
- 请求标头
- 查看源代码
- 接受:/
- 接受编码:gzip、deflate、br
- 接受语言:en,en-US;q=0.8,sv;q=0.6,fi;q=0.4
- 访问控制请求头:内容类型
- 访问控制请求方法:补丁
- 连接:保持活动
- 主机:本地主机:8888
- 来源:http://evil.com/
- 推荐人:http://localhost:3000/
- 用户代理:Mozilla/5.0(Macintosh;Intel Mac OS X 10_12_6)
- AppleWebKit/537.36(KHTML,如 Gecko)Chrome/61.0.3163.100Safari/537.36
- 查询字符串参数
- 查看源代码
- 查看 URL 编码
- _format:json
用 Firefox 测试,它可以工作,但它在 Chrome 中不起作用!已清空缓存并重新启动并进行硬重新加载无济于事.
Tested with Firefox and it works, but it doesn't work in Chrome! Have emptied caches and restarted and done a hard reload to no avail.
编辑 2:问题已解决.我在 Chrome 中安装了另一个 CORS 插件.如果有人在使用其他 CORS 插件时遇到同样的问题,请执行以下操作:
Edit 2: Problem solved. I installed another CORS plugin in Chrome. The following works in case anyone is facing the same problem with other CORS plugins:
https://chrome.google.com/webstore/detail/moesif-origin-cors-change/digfbfaphojjndkpccljibejjbppifbc
推荐答案
我也遇到过完全一样的事情.像你一样,只是 react、axios 和 chrome 的组合不起作用.
I've experienced exactly the same thing. Like you, just the combination of react, axios and chrome didn't work.
我通过将我的 CORS chrome 扩展更改为这个扩展来解决这个问题:https://chrome.google.com/webstore/detail/access-control-allow-cred/hmcjjmkppmkpobeokkhgkecjlaobjldi
I solved the issue by changing my CORS chrome extension to this one: https://chrome.google.com/webstore/detail/access-control-allow-cred/hmcjjmkppmkpobeokkhgkecjlaobjldi
这篇关于axios 补丁在 Chrome 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!