cpj
cpj

Reputation: 11

Sending more than one Web request

I have the following code as I am trying to send multiple requests to a Spectra tape library -

**

$results = Invoke-WebRequest -Uri "http://spectra1/gf/login.xml?username=administrator&password=xxxxxxx&forceFrontPanel
$results = Invoke-WebRequest -Uri "http://spectra1/gf/driveList.xml?action=list" -OutFile c:\temp\drivelist.txt

**

The first result is fine, it logs in but as soon as I send the second command it says:-

<?xml version="1.0"?>
<error>
  <message>You must go to login.xml and login before operating the library</message>
  <description>---- Error: No active session found.  
Visit login.xml to specify your username and password
</description>
</error>

Any help?

Upvotes: 1

Views: 1258

Answers (1)

n01d
n01d

Reputation: 1077

Toy should save your session with login and use it for the second request. Like this:

$results = Invoke-WebRequest -Uri "http://spectra1/gf/login.xml?username=administrator&password=xxxxxxx&forceFrontPanel" -SessionVariable spectra1Session
$results = Invoke-WebRequest -Uri "http://spectra1/gf/driveList.xml?action=list" -WebSession $spectra1Session -OutFile c:\temp\drivelist.txt

-SessionVariable spectra1Session to save session in variable $spectra1Session and then -WebSession $spectra1Session to use saved session.

Upvotes: 2

Related Questions