问题答案 12026年5月28日 20:39
How can I send cookie using NodeJs request GET module?
In Node.js, sending HTTP GET requests with cookies can typically be achieved using popular libraries such as or (which is deprecated but still has extensive examples and documentation). Below, I will use as an example to demonstrate how to send a GET request with cookies. First, ensure that is installed. If not, install it using npm: Next, we can write a simple function to send a GET request with cookies. Here is an example code snippet: In the above code, the second parameter of the method is a configuration object that includes the property. We set the header through this property, with the value being the cookie string we intend to send. This approach is suitable for scenarios where authentication information or session information needs to be included with the request, such as accessing a page that requires login. This example demonstrates how to use the library in Node.js to send an HTTP GET request with cookies. By adjusting the object, we can also send other types of HTTP header information.