简体   繁体   English

通过代理获取URL返回403错误

[英]Fetching URL through proxy returns 403 error

With the goal of avoiding all the CORS headaches, I setup my vue cli to proxy the API call through webpack: 为了避免所有CORS头痛,我设置了vue cli以通过webpack代理API调用:

config/index.js 配置/ index.js

proxyTable: {
  '/api': {
    target: 'https://remote',
    changeOrigin: true,
    '^/api': '/api'
  }
},

Visiting the URL directly in browser works, for example: http://localhost:8080/api/events 直接在浏览器中访问URL即可,例如: http://localhost:8080/api/events

However, if I try to fetch the url with axios, I get a 403 error: Error: "Request failed with status code 403" 但是,如果尝试使用axios提取URL,则会收到403错误: Error: "Request failed with status code 403"

Unfortunately the only reference I could find is this open issue . 不幸的是,我唯一可以找到的参考是这个未解决的问题

In my case, it doesn't work in Firefox or Chrome. 就我而言,它在Firefox或Chrome中不起作用。

This is a vue-cli 2 project, axios 0.18.0 , vue 2.5.2, webpack 3.6.0 , webpack-dev-server 2.9.1` 这是一个vue-cli 2项目,axios 0.18.0 ,vue 2.5.2, webpack 3.6.0 , webpack-dev-server 2.9.1`

Ah I see, in case it benefits anyone, for some reason, setting my API url as localhost was not working: 嗯,我知道,如果出于某种原因使任何人受益,请将我的API URL设置为localhost不起作用:

.env .ENV

API_URL=//localhost:8080/api

But the following works: 但是以下工作原理:

.env .ENV

API_URL=//127.0.0.1:8080/api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript:可以访问返回json的url,但是在获取时发生错误 - Javascript: can access url that returns json but when fetching, an error occurs 使用 gurnt-connect-proxy 代理到 cloudfront 得到 403 错误 - Use gurnt-connect-proxy proxy to cloudfront get 403 error 如何使用“ exec”网址而不是“ dev”网址从Google Apps脚本创建webhook。 Exec返回403错误 - How to create webhook from Google Apps Script using the “exec” url rather than “dev” url. Exec returns 403 Error jQuery-获取一个URL,该URL在前几次获取时返回404,然后返回200 - JQuery - Fetching a URL that returns 404 on first few fetches, then returns 200 jQuery FullCalendar返回http 403错误 - jquery FullCalendar returns http 403 error SharePoint REST 查询返回 403 禁止错误 - SharePoint REST Query returns 403 forbidden error 可变网址参数触发403禁止错误 - Variable URL parameter triggers 403 forbidden error Ajax跨域PHP代理403错误 - Ajax Cross-domain Php proxy 403 error 骨干网:在变量中提供JSON,而不是通过URL提取 - Backbone: Feed JSON in a variable instead of fetching through URL Javascript-从Dropbox加载图像返回403禁止错误 - Javascript - Loading Images from Dropbox returns 403 Forbidden Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM