【发布时间】:2014-08-13 14:26:09
【问题描述】:
我有一个使用 nginx 的 Web 服务器,配置了 HTTPS 和基本身份验证。
我正在尝试使用我的 WebClient 和 PowerShell 来查询它
$wc = new-object System.Net.WebClient
$wc.Credentials = Get-Credential
return $wc.DownloadString($url)
这适用于以下$urls
https://server.com
https://server.com/
https://server.com/directory/
https://server.com/page.php
https://server.com/directory/index.php
但是对于以下$urls,我得到The remote server returned an error: (401) Unauthorized.
https://server.com/directory
https://server.com/otherdirectory
https://server.com/directory/directory
起初我认为这是由于重定向,但考虑到一些工作示例,这没有意义。也许是我的 nginx 配置?
【问题讨论】:
-
“不起作用”是什么意思?
-
它得到一个 401,根据标题。可能应该在我的问题正文中提到这一点 - 现在更新谢谢。
-
您在使用普通浏览器导航时是否得到相同的行为?问题似乎很可能出在 Web 服务器/Web 应用程序的设置上。您可以在
nginx trailing slash或类似网站上进行互联网搜索,以找到配置 nginx 以按照您想要的方式处理此问题的方法。我从使用这些关键字的快速搜索中发现了几个有希望的链接。祝你好运! -
不,它在浏览器中工作正常
-
啊哈,但是浏览器重定向给一个斜线。我以前怎么没有注意到这一点
标签: https webclient basic-authentication http-status-code-301 http-status-code-401