gpt4 book ai didi

javascript - 选项(失败)仅适用于 Chrome 和 Firefox

转载 作者:数据小太阳 更新时间:2023-10-29 04:43:39 26 4
gpt4 key购买 nike

我发出了一个 POST 请求,请求一直处于等待状态,直到它最终失败。我监控了 nginx 日志和节点服务器日志,请求甚至没有注册。这适用于我测试过的任何其他人,但另一位同事除外。如果我使用边缘浏览器或不同的计算机,它工作正常。

我试图向其他(自定义)服务器发出 POST 请求,但它也卡在选项上。我还使用 jQuery 发出了 POST 请求,但它以同样的方式失败。

可能值得注意的是,我正在使用 withCredentials 标志。

标题:

Provisional headers are shown
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:GET
Origin:http://localhost:8080
Referer:http://localhost:8080/<path>
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36

请求:

  public login(user) {
const endpoint = `http://<url>`;

let headers = new Headers();
headers.append('Content-type', 'application/json');

return this.http
.post(endpoint, JSON.stringify(user), {
headers: headers,
});

}

我在我的组件中订阅了调用:

this._accountService.login(this.user)
.subscribe(res => {
console.log("logged in!");
if (res.json().status === "success") {
window.location.href = `/home/${this.org}/${this.product}`;
}
else {
// What other options are there?
console.log("Do something else maybe?");
}
},
err => {
this.invalidLogin = true;
console.log("Ye shall not pass!");
});

成功用户的标题

Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:<url>
Origin:<url>
Referer:<url>
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.33 Safari/537.36

来自 chrome://net-internals/#events

t=61869793 [st=    0] +REQUEST_ALIVE  [dt=60162]
--> has_upload = false
--> is_pending = true
--> load_flags = 34624 (DO_NOT_SAVE_COOKIES | DO_NOT_SEND_AUTH_DATA | DO_NOT_SEND_COOKIES | MAYBE_USER_GESTURE | VERIFY_EV_CERT)
--> load_state = 14 (WAITING_FOR_RESPONSE)
--> method = "OPTIONS"
--> net_error = -1 (ERR_IO_PENDING)
--> status = "IO_PENDING"
--> url = "<url>"
t=61929955 [st=60162] -HTTP_STREAM_PARSER_READ_HEADERS
--> net_error = -324 (ERR_EMPTY_RESPONSE)
t=61929955 [st=60162] -HTTP_TRANSACTION_READ_HEADERS
--> net_error = -324 (ERR_EMPTY_RESPONSE)
t=61929955 [st=60162] -URL_REQUEST_START_JOB
--> net_error = -324 (ERR_EMPTY_RESPONSE)
t=61929955 [st=60162] URL_REQUEST_DELEGATE [dt=0]
t=61929955 [st=60162] -REQUEST_ALIVE
--> net_error = -324 (ERR_EMPTY_RESPONSE)

我真的猜测这与我的浏览器中缓存的内容有关,但我真的找不到。我已经清除了所有 cookie 和任何可以存储的内容。我还能在哪里检查以清除东西?这显然是我的计算机/浏览器(和另一个不幸的人)本地的东西。

最佳答案

请尝试 subscribe() 到 observable。

return this.http
.post(endpoint, JSON.stringify(user), {
headers: headers,
}).subscribe(() => console.log("POST done!"));

关于javascript - 选项(失败)仅适用于 Chrome 和 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37807400/

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