如何使用 Powershell 通过基本身份验证登录网站 [英] How to login to website with basic authentication using Powershell

查看:60
本文介绍了如何使用 Powershell 通过基本身份验证登录网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PowerShell 登录网站并下载文件.

I am trying to use PowerShell to log into a website and download a file.

但是我无法让 PS 正确传递凭据.

However I can't get PS to pass the credentials properly.

这是我的PS:

$webclient = new-object System.Net.WebClient
$webclient.Credentials = new-object System.Net.NetworkCredential("username","password","domain")
$webpage = $webclient.DownloadString("url goes here")

这是我在 IE 中访问该站点时得到的登录框:

Here is the log in box I get when I hit the site in IE:

推荐答案

这就是我的工作.我相信关键部分是 CredentialCache 中的基本"

This is what I got to work. I believe the key part is the "Basic" in the CredentialCache

$webclient = new-object System.Net.WebClient
$credCache = new-object System.Net.CredentialCache
$creds = new-object System.Net.NetworkCredential("un","pw")
$credCache.Add("url", "Basic", $creds)
$webclient.Credentials = $credCache
$webpage = $webclient.DownloadString("url")

这篇关于如何使用 Powershell 通过基本身份验证登录网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆