I have to make HTTP requests to a server to fetch a particular page but it initially needs login. How do I send a POST request to the server by only using net module of node js and sockets created using it? The POST request needs a username and password.
-
1Possible duplicate of [How to make an HTTP POST request in node.js?](https://stackoverflow.com/questions/6158933/how-to-make-an-http-post-request-in-node-js) – Wainage Sep 17 '17 at 23:44
-
You could also use [fetch](https://www.npmjs.com/package/fetch) using the `POST` method and setting payload in options – lumio Sep 22 '17 at 09:25
-
This is not a duplicate question. I'm not finding the answer anywhere online. If someone who's passing does know the answer, please post. I haven't found a way for the **net** module to make a post request. I did however find making a request with the **https** module in [link](https://nodejs.dev/making-http-requests-with-nodejs) – The Bomb Squad Mar 01 '20 at 22:57
1 Answers
Here's the thing. I did a little investigation. I realised that the net module is really for IPC connections, while http connections are different. IPC stands for inter-process communication like how different users in a linux terminal can operate over the same resources. Http Connections are totally different.
Think of an IPC connection as someone meeting another. They are in contact with each other until one leaves.
Think of an http connection as you throwing a paper plane with info written on it to someone. All they do is throw another paper plane to you with info written on it as well.
The communication styles are quite different you see. I suggest you use http.request or https.request to send your information. Some details on how http requests work is on https://www.itcomprehension.com/ipc-ports-services-and-connections-explained

- 4,192
- 1
- 9
- 17