https - WebClient gets 401 when requesting a directory without a slash -
https - WebClient gets 401 when requesting a directory without a slash -
i have web server using nginx, configured https , basic authentication.
i'm attempting query webclient powershell
$wc = new-object system.net.webclient $wc.credentials = get-credential homecoming $wc.downloadstring($url)
this works fine next $url
s
https://server.com https://server.com/ https://server.com/directory/ https://server.com/page.php https://server.com/directory/index.php
but next $url
s, the remote server returned error: (401) unauthorized.
https://server.com/directory https://server.com/otherdirectory https://server.com/directory/directory
i thought @ first due redirection, wouldn't create sense given of working examples. perhaps it's nginx configuration?
i believe bug in webclient
class. here summary of interactions server:
------------------------------------------------------------------------ /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> ------------------------------------------------------------------------ /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> ------------------------------------------------------------------------ /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> ------------------------------------------------------------------------
at point, webclient throws exception, stating server returns error stated in question.
it should provide auth token 3rd request, or @ to the lowest degree respond 401 request auth token provided.
i have confirmed else (preferably .net 4.5.2) can take answer.
https webclient basic-authentication http-status-code-301 http-status-code-401
Comments
Post a Comment