A
A
AzizbekAzizbek2020-09-23 19:38:03
JavaScript
AzizbekAzizbek, 2020-09-23 19:38:03

How to send a request to the active localhost port using the html page opened on the computer?

It doesn't matter which function to use for this (fetch, XMLHttpRequest)
Is this even possible and how?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
VadimKholodilo, 2020-09-23
@VadimKholodilo

XHR will not allow you to send a request to any random port and address. Google same origin policy. You can turn it off, but I don't remember how. Another solution would be to use WebSockets, but the application listening on your localhost needs to support WebSockets.

N
Nadim Zakirov, 2020-09-23
@zkrvndm

Create a frame on the page, place a form in it, and initiate its submission with an external script. This method does not require writing CORS headers, although it certainly has a minus, you will not be able to read the server response. Suitable purely for one-way transfer of information.
If you want to make a classic AJAX request to your localhost, reading the response, then you first need to set the Access-Control-Allow-Origin header in NodeJS.

R
rPman, 2020-09-26
@rPman

If your page is opened via an unencrypted http channel, then you can easily send GET requests to any other domains, for example, images are loaded and displayed, which means you can encode your data in this request and transfer it to your local server.
ps Thus, you can send GET requests over the client's local network, scanning it for example for the presence of machines and services, and this is getting very important information from inside the network. For example, I have already seen https
three times, at different times://127.0.0.1:7070 request when entering the personal account of Sberbank online (anydesk hangs on this port) this rarely happens, it is difficult to track without special preparation (I generally noticed it because I have added a self-written certificate for localhost in my browser, and now firefox warns any attempts to open an encrypted channel with it)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question