0

HTTPS 및 기본 인증으로 구성된 nginx를 사용하는 웹 서버가 있습니다.슬래시가없는 디렉토리를 요청할 때 WebClient가 401을 얻습니다.

내가 PowerShell을 내 웹 클라이언트로 쿼리를 시도하고있어

$wc = new-object System.Net.WebClient 
$wc.Credentials = Get-Credential 
return $wc.DownloadString($url) 

이 다음 $url

https://server.com 
https://server.com/ 
https://server.com/directory/ 
https://server.com/page.php 
https://server.com/directory/index.php 

그러나 다음 $url들에 대한

, 내가 The remote server returned an error: (401) Unauthorized.

를 얻을 함께 잘 작동
https://server.com/directory 
https://server.com/otherdirectory 
https://server.com/directory/directory 

전나무에서 생각했습니다. 그것은 리다이렉션 (redirection)으로 인한 것이었지만, 몇 가지 작업 예제를 감안할 때 의미가 없습니다. 아마도 그것은 내 nginx 구성입니까?

+0

"작동하지 않는다"는 것은 무엇을 의미합니까? –

+0

제목 당 401을 얻습니다. 아마 내 질문의 본문에 언급 했어야 - 지금 감사합니다. – Nacht

+0

일반 브라우저로 탐색 할 때도 동일한 문제가 발생합니까? 문제는 웹 서버/웹 응용 프로그램의 설정과 관련이 있습니다. 'nginx trailing slash' 또는 유사한 방법으로 인터넷 검색을 수행하여 원하는 방식으로 nginx를 구성하는 방법을 찾을 수 있습니다. 나는 그 키워드를 사용하여 빠른 검색에서 몇 가지 유망한 링크를 발견했다. 행운을 빌어 요! –

답변

0

저는 현재이 버전이 WebClient 클래스의 버그라고 생각합니다. 이 시점에서

------------------------------------------------------------------------ 
GET /directory HTTP/1.1 
Host: example.com 
------------------------------------------------------------------------ 
HTTP/1.1 401 Unauthorized 
Server: nginx/1.4.6 (Ubuntu) 
Date: Fri, 27 Jun 2014 02:37:45 GMT 
Content-Type: text/html 
Content-Length: 203 
Connection: keep-alive 
WWW-Authenticate: Basic realm="sup" 

<html> 
<head><title>401 Authorization Required</title></head> 
<body bgcolor="white"> 
<center><h1>401 Authorization Required</h1></center> 
<hr><center>nginx/1.4.6 (Ubuntu)</center> 
</body> 
</html> 
------------------------------------------------------------------------ 
GET /directory HTTP/1.1 
Authorization: Basic bmFjaHQ6aGVsbG8= 
Host: example.com 
------------------------------------------------------------------------ 
HTTP/1.1 301 Moved Permanently 
Server: nginx/1.4.6 (Ubuntu) 
Date: Fri, 27 Jun 2014 02:37:46 GMT 
Content-Type: text/html 
Content-Length: 193 
Location: http://example.com/directory/ 
Connection: keep-alive 

<html> 
<head><title>301 Moved Permanently</title></head> 
<body bgcolor="white"> 
<center><h1>301 Moved Permanently</h1></center> 
<hr><center>nginx/1.4.6 (Ubuntu)</center> 
</body> 
</html> 
------------------------------------------------------------------------ 
GET /directory/ HTTP/1.1 
Host: example.com 
------------------------------------------------------------------------ 
HTTP/1.1 401 Unauthorized 
Server: nginx/1.4.6 (Ubuntu) 
Date: Fri, 27 Jun 2014 02:37:47 GMT 
Content-Type: text/html 
Content-Length: 203 
Connection: keep-alive 
WWW-Authenticate: Basic realm="sup" 

<html> 
<head><title>401 Authorization Required</title></head> 
<body bgcolor="white"> 
<center><h1>401 Authorization Required</h1></center> 
<hr><center>nginx/1.4.6 (Ubuntu)</center> 
</body> 
</html> 
------------------------------------------------------------------------ 

웹 클라이언트는 서버가 질문에 명시된 오류를 반환한다는, 예외가 발생, 다음은 서버 내 상호 작용의 요약입니다.

아마도 인증 토큰에 세 번째 요청을 제공해야하며, 최소한 제공된 인증 토큰과 함께 다른 요청으로 401에 응답해야합니다.

이 답변을 수락 할 수 있도록이 권한을 다른 사람 (가능하면 .NET 4.5.2)에서 확인하고 싶습니다.

관련 문제