No 'Access-Control-Allow-Origin' header is present on the requested resource + The response had HTTP status code 401

后端 未结 2 1647
情话喂你
情话喂你 2021-01-02 09:13

XMLHttpRequest cannot load http://192.168.1.253:8080/... No \'Access-Control-Allow-Origin\' header is present on the requested resource. Origin \'http://l

2条回答
  •  难免孤独
    2021-01-02 09:52

    The response had HTTP status code 401.

    401 indicates an authentication error. The error message in the question isn’t for a response from a preflight OPTIONS request. It instead seems to be for the actual GET request you’re trying to send.

    So based on that error message, it seems the most likely scenario is that the browser’s preflight OPTIONS request succeeded but your GET request is not succeeding due to authentication failure.

    So the server’s returning a 401 response/error page. And many/most web servers aren’t configured to send the Access-Control-Allow-Origin response header for error responses/pages. That’s the only reason you’re also getting a message about that header being missing.

    But that missing header for the error response is not the cause of your problem; instead, the 401 is.

    So it seems you probably want to figure out what’s causing the server to send a 401 response—why you’re getting an authentication failure. If you fix that it seems likely you’ll get a response from the server that includes the Access-Control-Allow-Origin response header as expected.

提交回复
热议问题