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

本地打包出来的代码,扔到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请求?

阅读 3.9k
1 个回答
新手上路,请多包涵

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进