Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy无法设置header头的问题 #2905

Open
wind8866 opened this issue Jan 3, 2020 · 5 comments
Open

proxy无法设置header头的问题 #2905

wind8866 opened this issue Jan 3, 2020 · 5 comments

Comments

@wind8866
Copy link

wind8866 commented Jan 3, 2020

Question(提问)

由于后端接口服务器使用的是虚拟主机,所以本地代理服务器的请求头必须携带Host字段。
我根据webpack与http-proxy-middleware文档做了如下配置:

// vue.config.js
module.exports = {
  devServer: {
    	proxy: {
	  '/api': {
	    target: 'https://example.com',
	    headers: {
	    	host: 'example.com'
	    },
	    changeOrigin: true
	  }
	}
  }
}

我本地服务是http://localhost:9530,我是用postman加上请求头访问类似http://localhost:9530/api/user的接口可以访问通。

但是我配置的header字段不生效,浏览器里面接口请求一直返回308,如图。

Screenshot or Gif(截图或动态图)

image

Other relevant information(格外信息)

线上服务器是https,我本地localhost是http,不知这个有没有影响。

@mayunhai
Copy link
Contributor

mayunhai commented Jan 3, 2020

http不能请求 https接口

@xdlStrive
Copy link

或许你是要在proxy里加个参数
secure: false

@ghost
Copy link

ghost commented Jan 12, 2021

target: 'http://some-host.test:1234',
headers: {
  'Host': 'some-host.test'
}   

注意要'Host': 'some-host.test' 这么写,我也是尝试多次才发现,和文档不符。

@ShadowWaIker
Copy link

```js
target: 'http://some-host.test:1234',
headers: {
  'Host': 'some-host.test'
}   

注意要'Host': 'some-host.test' 这么写,我也是尝试多次才发现,和文档不符。

我试了下

headers: {
  Host: 'some-host.test'
} 

这样也是可以的,主要是 H 得大写

@zhihuifanqiechaodan
Copy link

zhihuifanqiechaodan commented Oct 20, 2021

🤔️这里你不是应该在axios中配置请求头嘛。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants