账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    github托管代码axios post请求405怎么解决?
    56
    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请求?

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部