问题是我从供应商处获得了一个脚本来从数据库中提取数据。 该脚本遇到了Invoke-WebRequest部分的问题。
这是脚本:
$url = @'
https://demo.liquidwarelabs.com/lwl/api?json={"inspector":"0","basis":"users","date":"yesterday","limit":"0","columns":"user_name,login_count","output":"1:html","header":"1"}
'@
$output = "c:\export\Tier1\view1.csv"
Invoke-WebRequest $url -OutFile $output
以下是我得到的错误:
Invoke-WebRequest:底层连接已关闭:An 发送时发生意外错误。在C:\ Scripts \ 3.ps1:38 char:1 + Invoke-WebRequest $ url -OutFile $ output + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation:(System.Net.HttpWebRequest:HttpWebRequest)[Invoke-WebRequest], 引发WebException + FullyQualifiedErrorId:WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
答案 0 :(得分:0)
您可能需要对JSON进行URL编码:
$url = 'https://demo.liquidwarelabs.com/lwl/api?json='
$json = '{"inspector":"0","basis":"users","date":"yesterday","limit":"0","columns":"user_name,login_count","output":"1:html","header":"1"}'
$encodedjson = [System.Web.HttpUtility]::UrlEncode($json)
$output = "c:\export\Tier1\view1.csv"
Invoke-WebRequest ($url+$encodedjson) -OutFile $output