gpt4 book ai didi

Angular 2 http没有设置标题

转载 作者:太空狗 更新时间:2023-10-29 17:36:01 25 4
gpt4 key购买 nike

我正在这样设置我的 header 和 http 调用:

 var headers = new Headers();
headers.set('Authorization','Bearer xxxxxxxxxxx');

this.http.get('http://localhost:8080/outputEndpoints', {
headers: headers
}).
map(res => res.text())

.subscribe(
data=> console.log(data),
error=> console.log("Getting Error")
);

有了这个,我希望 header 是:

Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:es,ca;q=0.8,en-GB;q=0.6,en;q=0.4,fr;q=0.2
Access-Control-Request-Headers:authorization, content-type
Authorization: "Bearer xxxxxxxxxxxx"
Access-Control-Request-Method:GET
Connection:keep-alive
Host:localhost:8080
Origin:http://localhost:3000
Referer:http://localhost:3000/
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36

相反,我得到以下信息(没有 token 授权):

Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:es,ca;q=0.8,en-GB;q=0.6,en;q=0.4,fr;q=0.2
Access-Control-Request-Headers:authorization, content-type
Access-Control-Request-Method:GET
Connection:keep-alive
Host:localhost:8080
Origin:http://localhost:3000
Referer:http://localhost:3000/
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36

编辑:

一般信息是:

Request URL:http://localhost:8080/outputEndpoints
Request Method:OPTIONS
Status Code:401
Remote Address:[::1]:8080

所以 OPTIONS 调用失败了。在其他应用程序中,一旦接受了 OPTIONS 调用,它就会发出 GET 请求,您可以在其中找到已设置的身份验证 token 。这意味着由于某种原因,OPTION 调用未被接受。

当使用 CURL 或 SOAP UI 进行调用时,它工作正常,所以我认为这不是 CORS 的问题。我说得对吗?

任何想法或指南都会非常有帮助。

最佳答案

我认为是 headers.append 而不是 headers.set。尝试改变你的方法,看看它是否有效。

关于Angular 2 http没有设置标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42118733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com