github托管代码axios post请求405怎么解决?

发布于 2022-09-11 20:26:19 字数 1708 浏览 21 评论 0

本地打包出来的代码,扔到Apache下运行的时候是正常的,所有请求都能正确处理。

axios.defaults.headers.post.Accept = 'application/json, text/javascript, */*; q=0.01';
axios.defaults.headers.post['X-Requested-With'] = 'xmlhttprequest';
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
axios.interceptors.request.use((config) => {
  config.data = qs.stringify(config.data, {arrayFormat: 'brackets'});
  return config;
});

axios也已经做了配置。
但是提交到github,开启homepage访问的时候,get请求正常,post请求405报错了。
本地代码的请求头如下:

Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive
Content-Length: 38
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Host: test.com
Origin: http://test.com
Referer: http://test.com/vue-ts/cart
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1
X-Requested-With: xmlhttprequest

github上面的请求头如下:

:authority: no2015.github.io
:method: POST
:path: /vue-ts/static/api/updateCart.json
:scheme: https
accept: application/json, text/javascript, */*; q=0.01
accept-encoding: gzip, deflate, br
accept-language: zh-CN,zh;q=0.9
content-length: 94
content-type: application/x-www-form-urlencoded; charset=UTF-8
origin: https://no2015.github.io
referer: https://no2015.github.io/vue-ts/cart
user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1
x-requested-with: xmlhttprequest

是不是缺少了什么配置?还是github禁止了我的post请求?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热风软妹 2022-09-18 20:26:19

不是GitHub禁止了你的post请求,是静态页面不允许post请求,需要把post方法改为get方法,我和你碰到了一样的问题,但我现在也没有解决,你解决了吗?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文