javascript – 仅在Chrome和Firefox上的选项(失败)

前端之家收集整理的这篇文章主要介绍了javascript – 仅在Chrome和Firefox上的选项(失败)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我发出一个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和任何东西.我还能在哪里检查清楚的事情?这显然是我的电脑/浏览器(以及另一个不幸的人)本地的东西.

解决方法

请尝试订阅()到observable.
return this.http
  .post(endpoint,{
    headers: headers,}).subscribe(() => console.log("POST done!"));
原文链接:https://www.f2er.com/js/157880.html

猜你在找的JavaScript相关文章