Heim  >  Fragen und Antworten  >  Hauptteil

javascript - Beim Senden einer Anfrage gibt es oft eine weitere Anfrage, bevor sie initiiert wird. Was sind die Gründe?

Schnittstellen sind alle CORS-domänenübergreifend

Eine zusätzliche Anfrage: Anfragemethode: OPTIONEN, keine Parameter übergeben

Zusätzliche Request-Response-Header

Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers
Access-Control-Allow-Methods:POST, GET, PUT, OPTIONS, DELETE
Access-Control-Allow-Origin:*
Access-Control-Max-Age:3600
Allow:GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH
Connection:keep-alive
Content-Length:0
Date:Fri, 05 May 2017 09:27:40 GMT
Server:WildFly/10
X-Powered-By:Undertow/1

Antwortheader für normale Anfragen

Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers
Access-Control-Allow-Methods:POST, GET, PUT, OPTIONS, DELETE
Access-Control-Allow-Origin:*
Access-Control-Max-Age:3600
Connection:keep-alive
Content-Type:application/json;charset=UTF-8
Date:Fri, 05 May 2017 09:27:41 GMT
Server:WildFly/10
Set-Cookie:JSESSIONID=Zv7WiKxKZFNkE6ihLsGfGwYF8ZEFNEFxENl7rNLW.localhost; path=/bridge
Transfer-Encoding:chunked
X-Powered-By:Undertow/1
滿天的星座滿天的星座2713 Tage vor526

Antworte allen(4)Ich werde antworten

  • 漂亮男人

    漂亮男人2017-05-17 10:05:33

    跨域 post请求,需要option一次

    Antwort
    0
  • 巴扎黑

    巴扎黑2017-05-17 10:05:33

    楼上正解,如果是简单的跨域请求,建议不要使用POST

    Antwort
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-17 10:05:33

    你curl一下你的请求,应该就不会有这样的预请求

    Antwort
    0
  • PHPz

    PHPz2017-05-17 10:05:33

    1楼正解,跨域请求会先option一次到服务端,经过服务端验证通过后,在发送请求

    Antwort
    0
  • StornierenAntwort