我试图建立发送401验证错误我与正常的HTML响应沿所有请求的服务器的连接。例如 不过,我也想读是非常久远的,这样我可以解析发送的HTML响应。使用的LiveHTTPHeaders捕获的示例头交换: 显然,内容长度为非零。火狐表明它的JavaScript。

https://172.31.1.251:1003/fgtauth?73e285357b2dc5cc
Request:
GET /fgtauth?73e285357b2dc5cc HTTP/1.1
Host: 172.31.1.251:1003
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b4) Gecko/20090423 Firefox/3.5b4 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

Response:
HTTP/1.x 401 Unauthorized
WWW-Authenticate: Fortigate
Content-Length: 1091
Connection: Keep-Alive
Cache-Control: no-cache
Content-Type: text/html

在这一点上,形式在Firefox打开,要求我输入我的用户名和密码。

https://172.31.1.251:1003/

Request:
POST / HTTP/1.1
Host: 172.31.1.251:1003
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b4) Gecko/20090423 Firefox/3.5b4 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: https://172.31.1.251:1003/
Content-Type: application/x-www-form-urlencoded
Content-Length: 93
magic=73e285357b2dc5cc&username=uuxx&password=xxuu&4Tredir=http%3A%2F%2Fwww.google.com%2F


Response:
HTTP/1.x 401 Unauthorized
WWW-Authenticate: Fortigate
Content-Length: 924
Connection: Keep-Alive
Cache-Control: no-cache
Content-Type: text/html

在这一点上,我重定向到另一个网址。然而,我的问题是如何让lenght 924与401未授权一起发送的内容,因为这些内容会帮助我在做什么,我想进一步做。但很行:

WebResponse loginResponse = loginRequest.GetResponse();

抛出异常。

我会很感激的任何建议,以帮助我获得实际的内容。

感谢。

有帮助吗?

解决方案

您需要阅读WebExceptionResponse财产,像这样的:

WebResponse loginResponse;
try {
    loginResponse = loginRequest.GetResponse();
} catch(WebException ex) {
    if (ex.Status == WebExceptionStatus.ProtocolError) {
        loginResponse = ex.Response;
    } else
        throw;
}

//Do something with the response, and remember to dispose it.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top