进入同学录后查看某个班级的留言,得到该班级留言页面的地址为
http://alumni.chinaren.com/class/class_index.jsp?classuuid=********将这个地址COPY进一个TEXTBOX里,通过旁边一个按纽,把该页面的源文件写入一个STRING里,以便以后提取所需内容,这个事件该如何写代码?(WEBFROM)注,页面必须通过用户名和密码才能看见,而且页面是JSP页面大家帮帮忙啊~~~~~~~~~
http://alumni.chinaren.com/class/class_index.jsp?classuuid=********将这个地址COPY进一个TEXTBOX里,通过旁边一个按纽,把该页面的源文件写入一个STRING里,以便以后提取所需内容,这个事件该如何写代码?(WEBFROM)注,页面必须通过用户名和密码才能看见,而且页面是JSP页面大家帮帮忙啊~~~~~~~~~
解决方案 »
- .NET项目问题(急--在线等)
- 求大侠发发《编程之美——微软技术面试心得》
- 在线等!AJAX的autocompleteextender控件实现自动输入一定需要Web Service?
- gridview用css固定表头失效,请帮助
- 该字符串未被识别为有效的布尔值。谁帮我解决!~~分给谁
- 如何在cs中使用对话框?
- login控件登录后,如何在跳转页面提取UserID?
- 谁能用继承TextBox的方法,写一个只能输入数字的文本框控件???
- 类静态方法调用时是否比非静态方法执行效率快些?
- 高分求解:如何读取Oracle中的BLOB字段(为图片),在页面中显示图片??
- 一道逻辑题,困惑,可能我有个弯没有转过来!
- 急求:当点击datagrid控件中的EditCommandColumn的编辑按钮时,怎么控制datagrid控件里的输入框的属性,如最大输入字符个数?
能详细点吗?或者给点代码?谢谢了
using System.NetWebClient wc=new WebClient();
string url="http://alumni.chinaren.com/class/class_index.jsp?classuuid=********";byte[] response=wec.DownloadData(url);
string Result=Encoding.ASCII.GetString(response);
Console.writelIne(Result);
我用你的代码试过,但是中文全变成乱码了,另外还是没有解决密码和用户名的问题,虽然有页面,但是是没登陆的页面
Stream ReceiveStream = res.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("GB2312");
StreamReader sr = new StreamReader( ReceiveStream, encode );
String sHTML = sr.ReadToEnd();
...
see
http://www.csdn.com.cn/web/1776.htm
无法显示呀~~~~~````
Dim Post As String = ""
For Each s As String In PostData
Post += s + "&"
Next
Post = Post.Substring(0, Post.Length - 1)
Dim html As String = "" Dim encoding As Encoding = encoding.GetEncoding("GB2312")
Dim data As Byte() = encoding.GetBytes(Post)
Dim myRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
myRequest.Method = "POST"
myRequest.ContentType = "application/x-www-form-urlencoded"
myRequest.ContentLength = data.Length
Dim newStream As Stream = myRequest.GetRequestStream()
newStream.Write(data, 0, data.Length)
newStream.Close()
Dim resp As HttpWebResponse = CType(myRequest.GetResponse(), HttpWebResponse)
Dim sr As StreamReader = New StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default)
html = sr.ReadToEnd() Return html
End Function Public Shared Function GetDate(ByVal strUrl As String) As String
Dim html As String = "" Dim resp As HttpWebResponse
Dim req As HttpWebRequest = CType(HttpWebRequest.Create(strUrl), HttpWebRequest)
req.Timeout = 15000
resp = CType(req.GetResponse(), HttpWebResponse)
Dim sr As StreamReader = New StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default)
html = sr.ReadToEnd()
Return html
End Function第一个函数是用来向某个网址以post方式递交数据 你可以用来向登陆页面提交你的用户名称和密码 以登陆 然后使用第二个函数 取得 你需要的页面数据,你先第一个函数登陆 ,然后第二个函数就可以取得数据了!
对应到chinaren的就是:Dim postdata As String() = {"uid =你的用户名称","password=你的密码","utype=1"}其中utype=0表示用户是:ChinaRen用户
其中utype=1表示用户是:Sohu用户
其中utype=2表示用户是:手机用户
另外一个参数url就应该是:http://passport.sohu.com/login.jsp例如: Dim postdata As String() = {"uid =Contlu", "password=123456", "utype=1"}
Dim url As String = "http://passport.sohu.com/login.jsp" Dim html As String = PostDate(url, postdata)
Console.WriteLine(html)
Console.ReadLine()
就可以了 !不过还是不幸的告诉你chinaren 不容许从外部提交 就想CSDN一样!得到的结果是:
ERROR: 您不能直接调用此页面
{
string Post = "";
foreach (string s in PostData)
{
Post += s + "&";
}
Post = Post.Substring(0, Post.Length - 1);
string html = "";
Encoding encoding = encoding.GetEncoding("GB2312");
byte[] data = encoding.GetBytes(Post);
HttpWebRequest myRequest = ((HttpWebRequest)WebRequest.Create(url));
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
HttpWebResponse resp = ((HttpWebResponse)myRequest.GetResponse());
StreamReader sr = new StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default);
html = sr.ReadToEnd();
return html;
} public static string GetDate(string strUrl)
{
string html = "";
HttpWebResponse resp;
HttpWebRequest req = ((HttpWebRequest)HttpWebRequest.Create(strUrl));
req.Timeout = 15000;
resp = ((HttpWebResponse)req.GetResponse());
StreamReader sr = new StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default);
html = sr.ReadToEnd();
return html;
}