in

Is there a NodeJS equivalent to Powershell’s WebSession for multiple http requests


Is there a Node.js equivalent to using Powershell’s Invoke-WebRequest with WebSession parameters to persist state over multiple calls?

I am writing a Node application that makes multiple http calls to authenticate to a site and then download a file. The site is using ASP.NET session cookies in a way that I can’t decipher how to make properly-authenticated calls by manually managing cookies on my requests. I’m currently using node-fetch to make requests, but am not tied to a particular package.

I have a working mockup in Powershell, using Invoke-WebRequest and its WebSession parameter:

$loginURI = "$($baseURI)/Account/Login"
$response = Invoke-WebRequest -URI $loginuri -Method Get -SessionVariable session
$requestBody = @{
    'Email' = "$($username)"
    'Password' = "$($password)"
}
$loginResponse = Invoke-WebRequest -Uri $loginURI -Method Post -Body $requestBody -WebSession $session 

$downloadResult = Invoke-WebRequest -Uri $downloadBase -Method Get -WebSession $session -OutFile $outputFilePath

(assuming the URIs and credentials are defined)

Is there a Node equivalent to managing session in this way?



Source: https://stackoverflow.com/questions/70552369/is-there-a-nodejs-equivalent-to-powershells-websession-for-multiple-http-reques

Dummy Amazon clone with Bootstrap and React

Simple Python script that dumps a Wikidot wiki forum into JSON structures