0
xhr= new XMLHttpRequest(); //creates a new XMLHttpRequest
xhr.open("GET", "file.txt", false);
xhr.send(); // the request is sent
responsee = (xhr.responseText); // and the response is received

When the request is sent using 'xhr.send()' how can you get the source port for that particular request

  • 1
    Never set the async parameter of [`XMLHttpRequest.open()`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open) to false. It's deprecated and a terrible user experience. – Ivar Feb 07 '21 at 22:21
  • I don't think you can access the dynamic source port on the XHR, just like you cannot access the IP address. You could however write a server that sends back these as HTTP data - but notice they'll likely be those of the NAT anyway. – Bergi Feb 07 '21 at 22:32
  • You should know what is the port of your `xhr` otherwise how do you mind to open the connection? If no port are present in the url, the port `80` is selected as default. You can also find the url in the `xhr.url` after you have opened it. – DDomen Feb 07 '21 at 23:46
  • Nevermind, I have a theory that when a javascript is run on a website then, the remote port of that website is used to connect to any other site or IP through the XMLHttpRequest. I didn't think about that. –  Feb 08 '21 at 23:04

0 Answers0