0
プログラムでURLをプログラムで呼び出そうとしていますが、401の不正なエラーが発生しました。興味深いことに、私は、ログインセッションを開いてクロムブラウザでservicenowウェブサービスのURLを呼び出すと、私は正常にファイルをダウンロードすることができます。プログラムによるURLエクスポートの呼び出し - 返信(401)不正な応答
ここは私のPowerShellスクリプトです。
$WebClient=New-Object System.Net.WebClient
$credCatch=New-Object System.Net.CredentialCache
$urlServiceNow = "http://instancename.service-now.com/incident.do?csv"
try {
$creds=New-Object System.Net.NetworkCredential($username,$password)
$credCatch.Add($urlServiceNow,"Basic",$creds)
$WebClient.Credentials = $credCache
$WebClient.DownloadFile($urlServiceNow,$FilePath)
}
catch [System.Net.WebException]
{ # $_ is set to the ErrorRecord of the exception
if ($_.Exception.InnerException)
{
$_.Exception.InnerException.Message }
else {
$_.Exception.Message
}
}
使用しているアカウントでBasic Authを使用する権限がありますか? – ansario