Tampermonkey forces HTTPS instead of HTTP - GM_xmlhttprequest()

149 views Asked by At

I am trying to send a GET request to my server, but it cannot handle it.

The problem is that my Tampermonkey script sends the request to https://123.456.789.012:8000 instead of http://123.456.789.012:8000.

My script:

        GM_xmlhttpRequest({
            method: "GET",
            url: "http://123.456.789.012:8000",
            headers: {
                "Content-Type": "application/json"
            },
            responseType: "json",
            onload: function(response) {
                console.log("Got response:", response);
            },
            onerror: function(a) {
                console.log("error", a);
            }
        });

With connection declared:

// @connect http://123.456.789.012:8000

Calling it results in an error, where I can see:

DONE: 4
HEADERS_RECEIVED: 2
LOADING: 3
OPENED: 1
RESPONSE_TYPE_ARRAYBUFFER: "arraybuffer"
RESPONSE_TYPE_BLOB: "blob"
RESPONSE_TYPE_DOCUMENT: "document"
RESPONSE_TYPE_JSON: "json"
RESPONSE_TYPE_STREAM: "stream"
RESPONSE_TYPE_TEXT: "text"
UNSENT: 0
finalUrl: "https://123.456.789.012:8000/"
readyState: 4
response: undefined
responseHeaders: ""
responseText: ""
responseXML: undefined
status: 0
statusText: ""

We can see, that the request was sent to https address.

Obviously, this is just an example address, but works similarly. I tried to send this request by browser (by default through http) and it worked. When doing it by the script, the server receives it, but can't do anything with it.

code 400, message Bad request version

I found out, that this is because of https in the request. So is there any way to force Tampermonkey to send the request through http?

0

There are 0 answers