17

I am making a request with fetch at the client side with this code:

    var request = new Request(`http://ip:8080/click?url=${value}`, {
        method: 'GET',
        headers: new Headers({
            "Content-Type": "application/json"
        }),
    });
    fetch(request)

but when the browser makes the request, it automatically changes the URL with https protocol:

https://ip:8080/click?url=${value}

Note: the webpage has SSL encryption

Subsequently, I get this error on the webpage console: Failed to load resource: net::ERR_CONNECTION_CLOSED

6
  • The server doesn't support https requests, when I'm testing the webpage on my local browser I don't have any problem, but when doing it on the webpage with SSL encryption then the error happens. Commented Sep 22, 2020 at 17:28
  • What ?! you write in the comment the server "dosn't support https" and in your post, "the webpage has ssl encryption" ?! Commented Sep 22, 2020 at 17:35
  • yes, the webpage hosting has SSL encryption. The server where the API resides doesn't support https requests Commented Sep 22, 2020 at 17:41
  • I think your problem is CORS: en.wikipedia.org/wiki/Cross-origin_resource_sharing Commented Sep 23, 2020 at 6:18
  • @Marc How can it be a CORS problem since the changes from http to https is done by the browser? Commented Jun 30, 2021 at 10:53

1 Answer 1

13

I had the same problem and the reason was the following line in the head section:

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

It replaces every http requests with https.

Sign up to request clarification or add additional context in comments.

2 Comments

Note that this can also come from the HTTP headers of the page's response.
This was the issue for me in my template. I think this is something folks should check when they see unpredictable behavior.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.