Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PowerShell是否不为非默认端口发送身份验证标头?_Powershell - Fatal编程技术网

PowerShell是否不为非默认端口发送身份验证标头?

PowerShell是否不为非默认端口发送身份验证标头?,powershell,Powershell,我注意到一些奇怪的事情。。。在Powershell中,如果我尝试以下操作: $uri = new-object System.Uri("http://builds.strongbadia.egg:8080/builds/package.tar.bz2") $clnt = new-object System.Net.WebClient $clnt.Credentials = new-object System.Net.NetworkCredential($username, $password)

我注意到一些奇怪的事情。。。在Powershell中,如果我尝试以下操作:

$uri = new-object System.Uri("http://builds.strongbadia.egg:8080/builds/package.tar.bz2")
$clnt = new-object System.Net.WebClient
$clnt.Credentials = new-object System.Net.NetworkCredential($username, $password)
$clnt.DownloadFile($uri, "package.tar.bz2")
$auth = 'Basic ' + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password ))
$clnt.Headers.Add('Authorization', $auth)
未发送“授权”标题(通过Wireshark确认)。即使我使用凭据缓存,并特别说明应使用基本身份验证:

$cred = new-object System.Net.NetworkCredential($username, $password)
$credcache = new-object System.Net.CredentialCache
$credcache.Add($uri, "Basic", $cred)
$clnt.Credentials = $credcache
它根本不发送标题。相反,我必须做到以下几点:

$uri = new-object System.Uri("http://builds.strongbadia.egg:8080/builds/package.tar.bz2")
$clnt = new-object System.Net.WebClient
$clnt.Credentials = new-object System.Net.NetworkCredential($username, $password)
$clnt.DownloadFile($uri, "package.tar.bz2")
$auth = 'Basic ' + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password ))
$clnt.Headers.Add('Authorization', $auth)
只有在那个时候,“授权”头才会被发送,这基本上是因为我把东西塞进了PowerShell的喉咙里


知道这是一个已知的缺陷还是我做错了什么吗?我似乎找不到它的引用。

我以前确实看到过这一点,基本上,.Net库在发送凭据之前会等待来自服务器的验证查询。问题是,一些服务器永远不会发送请求,这就是为什么您永远看不到添加头的原因。您的方式工作的原因是您显式地将头强制到headers集合上

而且它不仅仅是PowerShell,它在任何.Net语言中都会发生