【问题标题】:Sending more than one Web request发送多个 Web 请求
【发布时间】:2016-12-20 11:04:58
【问题描述】:

当我尝试向 Spectra 磁带库发送多个请求时,我有以下代码 -

**

$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

**

第一个结果很好,它会登录,但我一发送第二个命令,它就会说:-

<?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>

有什么帮助吗?

【问题讨论】:

    标签: powershell


    【解决方案1】:

    Toy 应该保存您的登录会话并将其用于第二个请求。像这样:

    $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 将会话保存在变量$spectra1Session 中,然后-WebSession $spectra1Session 使用保存的会话。

    【讨论】:

    • 这很奏效 - 非常感谢,已经为此奋斗了一段时间!
    • @cpj 如果适合您的情况,请accept the answer。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-26
    • 1970-01-01
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多