Is there any faste way to download content from a website?
-
Wednesday, August 15, 2012 12:51 PM
This is my code now:
private string downloadContent()
{
try
{
WebRequest request = WebRequest.Create(url);
request.Method = "GET";
response = request.GetResponse();
Stream stream = response.GetResponseStream();
reader = new StreamReader(stream);
string content = reader.ReadToEnd();
return content;
}
catch
{
return error;
}
}This is the site:
http://chatroll.com/testingsI did that when im writing someting there in the chat so every n seconds it will show me what i wrote in my program textBox1 and also write it on a text file logger on my hard disk.
The problem is that sometimes if im typing somethings very fast one after one in the chat fro example typing: hello(enter),Hi(enter),Daniel(enter)....sometimes Hi will not be show in my program since its so fast i think the download of the content does not have enough time to download it so fast.
Is there any faster way to download the page source and handle it ? Maybe the way im downloading it is not so fast ?
You can see my project here:
https://skydrive.live.com/redir?resid=3B8A7D9F66FF985B!171&authkey=!AFO6EmoF38MtkKQ
danieli
- Moved by Bob Wu-MTMicrosoft Contingent Staff Monday, August 20, 2012 11:24 AM (From:Windows Forms General)
All Replies
-
Monday, August 20, 2012 11:24 AM
Hi danieli,
I move it to Network Class Library (System.Net) forum for better support.
Best Regards,
Bob Wu [MSFT]
MSDN Community Support | Feedback to us
-
Tuesday, August 21, 2012 9:52 AMYou shouldn't use ReadToEnd() method because there is no end until the connection closes. Instead you should read bytes until you get a line return. Reading faster is not a solution in this case. the delay could be at the far end not sending the message back while the message is being processed on the server.
jdweng
-
Wednesday, August 22, 2012 2:34 AM
Emmm... I think ReadToEnd() is the right thing to do here because the payload is short. And remember, this is web download and not TCP network stream so Chocolade shouldn't hold the connection longer than needed. (Or it'll choke the web server's connections)
That said, the direction is correct - Chocolade should consider group the messages to send in one go so all messages in the buffer are sent, and process the line breaks later on the client.
Since you're using WebClient to download, you can control the frequency to download the data so you won't push the server too hard.
-
Tuesday, August 28, 2012 11:32 PM
Try this(I converted it from VB, let me know if theres a problem.)
public string DownloadContent(string url) { string Result = string.Empty; using (Net.WebClient Webclient = new Net.WebClient()) { Result = Webclient.DownloadString(url); } return Result; }
If you want something you've never had, you need to do something you've never done.
- Edited by Paul IshakMicrosoft Community Contributor Tuesday, August 28, 2012 11:32 PM

