Search code examples
node.jshttpwebservernode-fetch

How to send raw request using node-fetch?


node-fetch can be found here: https://github.com/node-fetch/node-fetch

I want to send a plain request such as:

GET /search?q=test HTTP/2
Host: www.bing.com
User-Agent: <someAgentName>
Accept: */*

I have no idea how to do that, or if it possible at all. If not, what can you recommend me to use?


Solution

  • I was quite unsatisfied with the help gave by this community... The answer is:

    node-fetch (and other similar libraries such as request) is not supposed to handle raw text. It will be built internally using the options user told (such as url, headers). If you want to send the raw text, you need to look into how these libraries works under the hood

    Taking HTTP as example, it is just a TCP socket, and the information exchanged is exactly the raw text block I posted in the question. So the solution is to make a TCP socket and that's it. You send the raw text through the socket