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
javascript fetch automatically changes http with https.
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).
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With