Cross-domain AJAX withCredentials, PHP returns header content-lenght, but no content

前端 未结 1 702
难免孤独
难免孤独 2021-01-28 11:57

I am trying to send a cross domain request from a page on one domain to a PHP server on an other domain. Everything works fine without credentials (I need session) but as soon a

相关标签:
1条回答
  • 2021-01-28 12:29

    When setting headerAccess-Control-Allow-Credentials to true, you cannot use a wildcard for header Access-Control-Allow-Origin. That is, a specific host must be specified.

    Instead of:

    Access-Control-Allow-Origin: *
    

    Use:

    Access-Control-Allow-Origin: http://safedomain.com
    

    You can even set the Access-Control-Allow-Origin header to the Origin header received in the request. Not sure about PHP, but using the Java Servlets API:

    String origin = request.getHeader("Origin");    
    request.setHeader("Access-Control-Allow-Origin", origin);
    
    0 讨论(0)
提交回复
热议问题