我正在尝试从我的各种远程发射器中抓取日期。我有一个品牌的发射器,我可以使用以下 c# 代码登录:
public static string getSourceCode(string url, string user, string pass)
{
SecureString pw = new SecureString();
foreach (char c in pass.ToCharArray()) pw.AppendChar(c);
NetworkCredential credential = new NetworkCredential(user, pw, url);
CredentialCache cache = new CredentialCache();
cache.Add(new Uri(url), "Basic", credential);
Uri realLink = new Uri(url);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(realLink);
req.Credentials = CredentialCache.DefaultNetworkCredentials;
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
string sourceCode = sr.ReadToEnd();
sr.Close();
resp.Close();
return sourceCode;
}
第二个品牌的发射器(我不愿公开网址)而不是返回请求用户名和密码的网页,而是返回一个请求用户名和密码的框。使用上面的代码只会返回一个未经授权的错误。
Fiddler 说当我成功登录该站点时会发送以下内容:
GET http(冒号斜杠)lasvegas3abn(*)dyndns(*)tv(PORT)125(斜杠)measurements(*)htm HTTP/1.1 接受:文本/html、应用程序/xhtml+xml、*/* 接受语言:en-US 用户代理:Mozilla/5.0(兼容;MSIE 10.0;Windows NT 6.2;WOW64;Trident/6.0;Touch) 接受编码:gzip,放气 主持人:lasvegas3abn.dyndns.tv:125 授权:基本 dXNlcjpsaW5lYXI= 连接:保持活动 DNT: 1
有什么建议么?