HTTp请求中的TCPClient

HTTp请求中的TCPClient

本文介绍了HTTp请求中的TCPClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试使用tcpClient从net获取html文件,而不是使用WebClient或WebRequest获取, 主要部分源代码如下: private void tcpconnect() { tcp = new TcpClient(" www.yahoo.com",80); tcp.NoDelay = false; tcp.ReceiveTimeout = 60000; tcp.ReceiveBufferSize = 25000; stream = tcp.GetStream(); byte [] send = Encoding.ASCII.GetBytes(" GET /index.html HTTP / 1.0\ \ n \\\ n \\ n    stream.Write(send,0,send.Length); byte [] receive = new byte [tcp.ReceiveBufferSize]; int lastreceive = stream.Read(receive,0,tcp.ReceiveBuffe rSize); string str = Encoding。 ASCII.GetString(receive,0,tcp.ReceiveBuff erSize); textBox1.Text = str; tcp.Close(); stream.Close(); } 但问题是,虽然我尝试运行这个函数,它没有为我读取所有的 html源代码,但只是一部分,我尝试运行两次读取 方法功能,它继续为我读。我认为那里 可能是其他一些功能,它们可以让我们检查html文件是否已经完成加载,但是我不知道是哪个是我和我找不到它通过msdn库找到。是否有人可以提供帮助? 感谢所有 i''m trying using the tcpClient to get a html file from net, instead ofusing WebClient or WebRequest,the main part of the source code is like this:private void tcpconnect(){tcp=new TcpClient("www.yahoo.com",80);tcp.NoDelay=false;tcp.ReceiveTimeout=60000;tcp.ReceiveBufferSize=25000;stream = tcp.GetStream();byte[] send = Encoding.ASCII.GetBytes("GET /index.html HTTP/1.0\r\n\r\n");stream.Write(send,0,send.Length);byte[] receive = new byte[tcp.ReceiveBufferSize];int lastreceive=stream.Read(receive,0,tcp.ReceiveBuffe rSize);string str = Encoding.ASCII.GetString(receive,0,tcp.ReceiveBuff erSize);textBox1.Text=str;tcp.Close();stream.Close();}but the problem is, while i try to run this function, it didn''t read all thehtml source code for me, but just a part, i try to run twice of the readmethod in the function, and it does continue reading for me. I think theremight be some other function which allow us to check whether the html file isfinished loading or not, but i''m dunno which is it and i can''t find itthrough the msdn library. Is that anyone could help?Thank for all推荐答案 这篇关于HTTp请求中的TCPClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 17:48