IE11 CORS rejecting OPTIONS on https

前端 未结 1 452
长发绾君心
长发绾君心 2021-01-19 09:44

IE11 for some reason is rejecting a PUT request but only when I use https. I have very hard time to find the issue as using http, localhost and other browsers works fine.

1条回答
  •  暖寄归人
    2021-01-19 10:33

    I have managed to find the issue.

    I saw this issue on https only because the portal and the host where on different domains. I could not replicate the issue on localhost because both the server and portal are on this same domain. This means the OPTION request was not sent and everything worked as expected. After running the portal on localhost and using IP address as a server URL instead of localhost the OPTION request was included in the request and I could replicate my issue.

    And the issue it self was down to following code on the server

        for ( String method : ["OPTIONS", "GET", "POST", "PUT", "DELETE"] ) 
        {
            headers.add( "Access-Control-Allow-Methods", method );
        }
    

    for some reason IE did not like multiple Access-Control-Allow-Methods headers. After changing code to the following issue was solved.

     List ALLOWED_METHODS = Arrays.asList( "OPTIONS", "GET", "POST", "PUT", "DELETE" );
     headers.add( "Access-Control-Allow-Methods", ALLOWED_METHODS );
    

    0 讨论(0)
提交回复
热议问题