问题是请求不到数据、下面是代码。求指教Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); IPHostEntry ipHost = Dns.GetHostEntry("www.baidu.com"); IPAddress ip = ipHost.AddressList.Where(i => { return i.AddressFamily.Equals(AddressFamily.InterNetwork);}).First(); StringBuilder sb = new StringBuilder();
//http://www.baidu.com/img/baidu_sylogo1.gif
sb.AppendLine("GET /img/baidu_sylogo1.gif HTTP/1.1");
sb.AppendLine("Accept: */*");
sb.AppendLine("Accept-Language: zh-CN");
sb.AppendLine("Content-Type: application/x-www-form-urlencoded");
sb.AppendLine("User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN)");
sb.AppendLine("Accept-Encoding: gzip, deflate");
sb.AppendLine("Host: www.baidu.com");
sb.AppendLine("Connection: Keep-Alive"); socket.Connect(new IPEndPoint(ip,80)); byte[] sendData = Encoding.UTF8.GetBytes(sb.ToString());
socket.Send(sendData); byte[] recive = new byte[1024]; while (socket.Receive(recive) != 0)
{
Console.WriteLine(Encoding.UTF8.GetString(recive));
} socket.Shutdown(SocketShutdown.Both); socket.Close();
//http://www.baidu.com/img/baidu_sylogo1.gif
sb.AppendLine("GET /img/baidu_sylogo1.gif HTTP/1.1");
sb.AppendLine("Accept: */*");
sb.AppendLine("Accept-Language: zh-CN");
sb.AppendLine("Content-Type: application/x-www-form-urlencoded");
sb.AppendLine("User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN)");
sb.AppendLine("Accept-Encoding: gzip, deflate");
sb.AppendLine("Host: www.baidu.com");
sb.AppendLine("Connection: Keep-Alive"); socket.Connect(new IPEndPoint(ip,80)); byte[] sendData = Encoding.UTF8.GetBytes(sb.ToString());
socket.Send(sendData); byte[] recive = new byte[1024]; while (socket.Receive(recive) != 0)
{
Console.WriteLine(Encoding.UTF8.GetString(recive));
} socket.Shutdown(SocketShutdown.Both); socket.Close();
解决方案 »
- 怎样减少dataGridView加载大量数据的时间?
- 关于C# 正则表达式
- winForm下,C#的类似XP左边常见任务那种侧边栏怎么做?
- C#在Web下根据数据,动态生成曲线!急急!!!!!!!!!!!!
- 求助,怎样读取Excel表格中的数据能高效一些?
- c# webBrowser1 里面的 iframe 赋值
- SSL server 发数据到client 用的啥加密方法?
- webform 登录错误 急!在线等
- 请问,在C#中如何取到当天的日期?
- 把tabControl控件的标签放到左边后,文字成是上下显示的,怎样可以做成左右现实的?
- 不知道c#里是否有类似WIN7 优化大师中类似tabcontral的第三方控件
- 请问,如何实现ListBox的多项拖放
你要是需要的话可以发给你。