【发布时间】:2017-03-07 08:48:50
【问题描述】:
我想从 URL 中读取 Json 字符串,但是当我使用 Chrome 网页时会显示这个字符串:
当我使用 C# WebBrowser 时,它要求我下载文件以阅读 我尝试使用 WebClient DownloadString,但该站点使用登录页面中的 cookie,并显示 arlert“请求无效”:
请帮助我,如果我的英语不好,我很抱歉
更新:这是我的代码:
wbTest.Navigate("http://authen.dzogame.com:8080/LauncherLogin.aspx?gid=200");
wbTest.Document.GetElementById("tbxUserName").SetAttribute("value", "7honda");
wbTest.Document.GetElementById("tbxPassword").SetAttribute("value", "111111");
wbTest.Document.GetElementById("btnLogin").InvokeMember("click");
更新 2:我尝试获取/设置 cookie,但它不起作用。
wb.Navigate("http://authen.dzogame.com:8080/LauncherLogin.aspx?gid=200");
Wait();
id = txtID.Text;
pass = txtPassword.Text;
wb.Document.GetElementById("tbxUserName").SetAttribute("value", id);
wb.Document.GetElementById("tbxPassword").SetAttribute("value", pass);
wb.Document.GetElementById("btnLogin").InvokeMember("Click");
Wait();
string cookie = wb.Document.Cookie;
WebClient wc = new WebClient();
wc.Headers.Add(HttpRequestHeader.Cookie, cookie);
string token = wc.DownloadString("http://authen.dzogame.com:8080/ReturnLogin.ashx");
【问题讨论】:
-
能否提供更多信息,例如您目前编写的代码等?
-
考虑
WebClient或HttpRequest? -
@Thematkinson 我更新了我的代码。
-
@LeiYang 本站使用cookie显示json字符串,authen.dzogame.com:8080/ReturnLogin.ashx登录后才显示,如果我在Webbrowser登录并在WebClient获取json字符串将是“Request Invaild”
-
cookies 可以通过程序设置在
WebClient或HttpRequest
标签: c# json winforms webbrowser-control