我正在尝试为此网页开发应用,以便用户能够登录并查看其详细信息(方案等)。
http://www.lectio.dk/lectio/317/default.aspx
然而,我在处理从网络上获取数据时非常陌生,而且这个页面似乎很难从中获取任何数据(不要判断我:D)。
该页面使用gzip 该页面有一些带有生成ID的隐藏字段,需要我使用用户名和密码提交 页面抱怨每个会话cookie丢失
以下是我的代码现在的样子:
首先是我的Mywebclient课程:
public class MyWebClient : SharpGIS.GZipWebClient
{
Uri _responseUri;
public CookieContainer CookieContainer { get; private set; }
public MyWebClient()
{
this.CookieContainer = new CookieContainer();
}
public MyWebClient(CookieContainer cookieContainer)
{
this.CookieContainer = cookieContainer;
}
public Uri ResponseUri
{
get { return _responseUri; }
}
protected override WebResponse GetWebResponse(WebRequest request, IAsyncResult result)
{
WebResponse response = base.GetWebResponse(request, result);
_responseUri = response.ResponseUri;
return response;
}
protected override WebRequest GetWebRequest(Uri address)
{
var request = base.GetWebRequest(address) as HttpWebRequest;
if (request == null) return base.GetWebRequest(address);
request.CookieContainer = CookieContainer;
return request;
}
}`
其次是调用加载的代码
string postdata = "m$Content$password2=" + HttpUtility.UrlEncode("PASSWORD") + "m$Content$username2=" + HttpUtility.UrlEncode("USERNAME");
navigatePostRequestBrowser(new Uri("https://www.lectio.dk/lectio/317/login.aspx"), postdata);
最后加载
protected void navigatePostRequestBrowser(Uri url, string postdata)
{
MyWebClient webClient = new MyWebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
webClient.Encoding = Encoding.UTF8;
webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(proxy_UploadStringCompleted);
webClient.UploadStringAsync(url , "POST", postdata);
}
我的UploadStringCompleted看起来像这样:
private void proxy_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
{
var response = e.Result;
}
我不知道这是否几乎是正确的,因为我已尝试在互联网上随处可见的几种解决方案。
请帮助我 - 我被困住了!
答案 0 :(得分:0)
我的解决方案是使用静态隐藏的webbrowser而不是webclient。