网站读取问题,急(我爸是李刚帮我哈哈)

yuha521 2010-10-22 06:32:50
URL = http://www.ibc123.com/head.aspx

       public string GetHTMLTCP(string URL)
{
string strHTML = "";//用来保存获得的HTML代码
TcpClient clientSocket = new TcpClient();
Uri URI = new Uri(URL);
clientSocket.Connect(URI.Host, URI.Port);
StringBuilder RequestHeaders = new StringBuilder();//用来保存HTML协议头部信息
RequestHeaders.AppendFormat("{0} {1} HTTP/1.1\r\n", "GET", URI.PathAndQuery);
RequestHeaders.AppendFormat("Connection:close\r\n");
RequestHeaders.AppendFormat("Host:{0}\r\n", URI.Host);
//RequestHeaders.AppendFormat("Cookie:{0}\r\n", cooke);
//RequestHeaders.AppendFormat("CookieContainer:{0}\r\n", cok);
RequestHeaders.AppendFormat("Accept:*/*\r\n");
RequestHeaders.AppendFormat("Accept-Language:zh-cn\r\n");
RequestHeaders.AppendFormat("User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)\r\n\r\n");
Encoding encoding = Encoding.Default;
byte[] request = encoding.GetBytes(RequestHeaders.ToString());
clientSocket.Client.Send(request);
//获取要保存的网络流
Stream readStream = clientSocket.GetStream();
StreamReader sr = new StreamReader(readStream, Encoding.Default);
strHTML = sr.ReadToEnd();
readStream.Close();
clientSocket.Close();
return strHTML;
}

读取到的是这样的。。。 是否还少了什么参数。 大家帮忙看下!! 实际我是想得到 验证码。 这不是页面的代码!!

HTTP/1.1 200 OK
Date: Fri, 22 Oct 2010 10:31:19 GMT
Server: Microsoft-IIS/6.0
Set-Cookie: ASP.NET_SessionId=55im2x55iui1pbqvb5clggye; path=/; HttpOnly
Connection: close
X-Powered-By: ASP.NET
Content-Type: text/html; charset=utf-8
Cache-Control: private
Content-Length: 55
X-AspNet-Version: 2.0.50727

<script>window.top.location.href='index.aspx?'</script>
...全文
214 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
种草德鲁伊 2010-10-23
  • 打赏
  • 举报
回复
魔兽史上多年的迷题终于破解了 whosyourdaddy









我爸是李刚
yuha521 2010-10-23
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 jshi123 的回复:]
访问这个页面时,需要有cookie,先访问下首页index.aspx得到cookie,再把cookie传过去

C# code

HttpWebRequest req1 = (HttpWebRequest)WebRequest.Create("http://www.ibc123.com/index.aspx");
req1.CookieContainer = new Co……
[/Quote]

谢谢 大哥。 。。。。 厉害 !!!
kkbac 2010-10-23
  • 打赏
  • 举报
回复
顶楼上的大牛. 收藏代码先..
jshi123 2010-10-23
  • 打赏
  • 举报
回复
访问这个页面时,需要有cookie,先访问下首页index.aspx得到cookie,再把cookie传过去

HttpWebRequest req1 = (HttpWebRequest)WebRequest.Create("http://www.ibc123.com/index.aspx");
req1.CookieContainer = new CookieContainer();
HttpWebResponse resp1 = (HttpWebResponse)req1.GetResponse();
resp1.Close();

HttpWebRequest req2 = (HttpWebRequest)WebRequest.Create("http://www.ibc123.com/head.aspx");
req2.CookieContainer = req1.CookieContainer;
HttpWebResponse resp2 = (HttpWebResponse)req2.GetResponse();
string strContext = new StreamReader(resp2.GetResponseStream(), Encoding.UTF8).ReadToEnd();
resp2.Close();
yuha521 2010-10-22
  • 打赏
  • 举报
回复
我爸是李刚。 这是网络经典话语。。 楼上的 注意素质
winner2050 2010-10-22
  • 打赏
  • 举报
回复
这种玩笑开不得。

你逢人叫爹。

你不是百家种?
你妈岂不是打乱种?
你爸不就成泻停封了?
yuha521 2010-10-22
  • 打赏
  • 举报
回复
主要问题还是 传入cookie问题, , 第一次
默然说话 2010-10-22
  • 打赏
  • 举报
回复
李刚是谁?
yuha521 2010-10-22
  • 打赏
  • 举报
回复
ddddddddddddddddddd
yuha521 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 kkbac 的回复:]
看在你爸的分上,明天给你测试.
[/Quote]

说话算数啊!!!

有李刚这个爸,还真牛了啊!
kkbac 2010-10-22
  • 打赏
  • 举报
回复

看在你爸的分上,明天给你测试.
miracle_lq 2010-10-22
  • 打赏
  • 举报
回复
本来你爸是李刚应该帮的,可惜不会
yuha521 2010-10-22
  • 打赏
  • 举报
回复
我读另外一个网站 一样的代码都没问题1!!
yuha521 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wuyq11 的回复:]
验证码图片是要通过读取其src属性后 再发送一次读取图片文件流
webbrower 读取
[/Quote]

问题是,我连页面都读取不了。。。 我直接用图片的地址,做登录 也不行。。。
种草德鲁伊 2010-10-22
  • 打赏
  • 举报
回复
·┏┓   ┏┓
┏┛┻━━━┛┻┓
┃       ┃
┃   ━   ┃
┃ ┳┛ ┗┳ ┃
┃       ┃
┃ ////  //// ┃
┃       ┃
┃    ◎   ┃
┃       ┃
┗━┓   ┏━┛
  ┃   ┃
  ┃   ┃
  ┃   ┗━━━┓
  ┃       ┣┓
  ┃       ┏┛
  ┗┓┓┏━┳┓┏┛
   ┃┫┫ ┃┫┫
    ┗┻┛ ┗┻┛
wuyq11 2010-10-22
  • 打赏
  • 举报
回复
验证码图片是要通过读取其src属性后 再发送一次读取图片文件流
webbrower 读取
yuha521 2010-10-22
  • 打赏
  • 举报
回复
哎 ,,, 都没人能解决吗???我愁了。 !!
fangxqian 2010-10-22
  • 打赏
  • 举报
回复
你爸牛~,可我还不懂.
mayonglong 2010-10-22
  • 打赏
  • 举报
回复
你爸牛~
yuha521 2010-10-22
  • 打赏
  • 举报
回复

public bool GetVerifyPic(ref string strPicUrl)
{
Stream responseStream = null;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.ibc123.com/head.aspx");
request.Method = "GET";
request.KeepAlive = true;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
// request.Headers.Add("Cookie", this.m_BaseInfo.strCookies);
request.Proxy = null;
// request.Referer = "http://www.ibc123.com/";
// request.AllowAutoRedirect = true;
request.Timeout = 5000;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
responseStream = response.GetResponseStream();
string strContext = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")).ReadToEnd();
response.Close();

}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
if (responseStream != null)
{
responseStream.Close();
}
return false;
}
return true;
}


这段代码页是一样得到却是 <script>window.top.location.href='index.aspx?'</script> 着急啊!!!!

7,774

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧