I use c # socket for baidu's web pages, but there is always a variety of problems such as the do {sl=ss. The Receive (res, off, 1024, 0). Off +=sl;
} while (sl==1024); And do {sl=ss. The Receive (res, off, 1024, 0). Off +=sl;
} while (ss. Available> 0); Can obtain the complete web page, probably read 2880 bytes returned, Do {sl=ss. The Receive (res, off, 1024, 0). Off +=sl;
} while (sl> 0); So we can get to complete web pages but one minute delay, how to get it? Thank you,
CodePudding user response:
Why web processing hard to use the socket? HttpWebRequest WebClient are much stronger than that one
CodePudding user response:
Ss. The Receive (res, off, 1024, 0) If you can understand his meaning, write their own
He gave 1024 buffer, mean maximum can read 1024, minimum between 0 and 1024
If there are eight apples, take three at a time, ask you what time to take the
3, of course, is to get enough time and he took the
So your decision condition is
Do
While (less than 1024)
CodePudding user response:
Of course as a web page, so you write is not enough, Because web pages according to the HTTP protocol, you simply put him as byte read not reasonable writing, your to decode HTTP protocol to
So we suggest that, if not don't want to study what is the HTTP protocol, if you not want to study what he make the wheels and blog garden (the so-called do not build the wheels, is not a good programmer series books) Please use httpclient directly
CodePudding user response:
Read page you with the operation of the socket, is equivalent to, and you want to go to 1000 kilometers of destination, and you choose your transportation to, instead of using the existing public transport, high-speed trains, planes, Or, do you want to build a house, should buy brick cement line normally, and you to build a brick factory, the equivalent of cement plant, such as You can first take a look at the socket, TCP, HTTP these concepts, then see httpclient object,
CodePudding user response:
Upstairs said good others building cars with a ready-made synthesis, are you still making wheels
Upstairs is Can also be so use WebClient wc=new WebClient (); String uri="http://www.baidu.com"; Stream, Stream=wc. OpenRead (uri); StreamReader sr=new StreamReader (stream); String strLine=""; While ((strLine=sr. ReadLine ())!=null) { Enclosing listBox1. Items. The Add (strLine); RichTextBox1. AppendText (strLine); } The sr. The Close ();