简体   繁体   English

发送带有标头的GET请求时已创建选项请求-Angular7

[英]Options request has created while sending GET request with headers - Angular7

在此处输入图片说明

When i send GET request along with headers(see username in the image),a Options request triggered by Angular instead of sending GET request that cause my request fail but it works fine without headers. 当我将GET请求与标头一起发送时(请参见图片中的用户名),由Angular触发的Options请求而不是发送导致我的请求失败的GET请求,但是没有标头的情况下它可以正常工作。 I have highlihted the Request method as you can see it is Options but it should be GET. 我已经高调了Request方法,因为您可以看到它是Options,但是应该是GET。

this._http
      .get(url,{ headers: {  'userName':'john' }} )

From your image it appears the server is only returning allow-headers for Content-Type & Accept. 从您的图像看来,服务器仅返回Content-Type&Accept的允许标题。

Try adding 'username' to this list. 尝试将“用户名”添加到此列表。

Note the OPTIONS request occurs as a result of CORS (and not Angular specifically). 请注意,OPTIONS请求是由于CORS (而不是Angular)而发生的。

Hope this helps. 希望这可以帮助。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM