Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript fetch automatically changes http with https

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

like image 250
ctb Avatar asked Sep 22 '20 17:09

ctb


People also ask

Does fetch use HTTP or https?

javascript fetch automatically changes http with https.

Does fetch work with HTTP?

Fetch API comes with a fetch () method that allows you to fetch data from all sorts of different places and work with the data fetched. It allows you to make an HTTP request, i.e., either a GET request (for getting data) or POST request (for posting data).

Does fetch follow redirects?

If it is "follow", fetch() API follows the redirect response (HTTP status code = 301,302,303,307,308). If it is "error", fetch() API treats the redirect response as an error. If it is "manual", fetch() API doesn't follow the redirect and returns an opaque-redirect filtered response which wraps the redirect response.

Is JavaScript fetch asynchronous?

Fetch API is an asynchronous web API that comes with native JavaScript, and it returns the data in the form of promises. You use several Web APIs without knowing that they are APIs. One of them is the Fetch API, and it is used for making API requests.


1 Answers

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.

like image 100
Karol Borkowski Avatar answered Oct 13 '22 23:10

Karol Borkowski