473,385 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dowload File

Hi,
I have problem with downloading a file using WebRequest and
HttpWebResponse.
Inorder to download this file i need to call to url that tells to
prepare the file for download,
and then i call to another url that downloads the file.
I have a problem with that because:

1. i do not know when the server finished the preparetion.
2.i checked the HttpStatusCode but he doen't changes
(myresponse.StatusCode).

the problem causes the application to download only a part of the file
and that because the server hasn't prepared the file yet.
if i give him Thread.Sleep(100000) i do get the full file, but the file
can be 100Mb and 10sec won't help.

the code is:
//Preparing the file todownload...
//---------------------------------------------------------------------------------------------------------
HttpWebRequest webRequest3 = WebRequest.Create(d1) as
HttpWebRequest;
webRequest3.KeepAlive = true;
webRequest3.Headers.Add("Keep-Alive", "300");
webRequest3.Headers.Add("Accept","text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
webRequest3.Headers.Add("Accept-Language",
"en-us,en;q=0.5");
webRequest3.Headers.Add("Accept-Encoding", "gzip,deflate");
webRequest3.Headers.Add("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");

webRequest3.CookieContainer = cookies;
HttpWebResponse myResponse3 =
(HttpWebResponse)webRequest3.GetResponse();

Thread.Sleep(10000);
Stream ReceiveStream3 = myResponse3.GetResponseStream();

//-----------------------------------------------------------------------------------

//Downloading ....
//--------------------------------------------------------------------------------------
Console.WriteLine("Connecting to download link...");
HttpWebRequest webRequest2 = WebRequest.Create(re) as
HttpWebRequest;
webRequest2.ContentType =
"application/x-www-form-urlencoded";
webRequest2.KeepAlive = true;
webRequest2.CookieContainer = cookies;
HttpWebResponse myResponse2 =
(HttpWebResponse)webRequest2.GetResponse();
Stream ReceiveStream2 = myResponse2.GetResponseStream();
Console.WriteLine("Downloading...");

Common.SaveStreamToFile(@"C:\scrapingtest\file.csv ",
ReceiveStream2);
Console.WriteLine("Done Downloading");

Thanks, Rony

Sep 19 '06 #1
1 2236
Asked and answered on the *other* newsgroup you posted this exact same
question to.

--
HTH,

Kevin Spencer
Microsoft MVP
Digital Carpenter

A man, a plan, a canal,
a palindrome that has gone to s**t.

"rony_16" <ro***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,
I have problem with downloading a file using WebRequest and
HttpWebResponse.
Inorder to download this file i need to call to url that tells to
prepare the file for download,
and then i call to another url that downloads the file.
I have a problem with that because:

1. i do not know when the server finished the preparetion.
2.i checked the HttpStatusCode but he doen't changes
(myresponse.StatusCode).

the problem causes the application to download only a part of the file
and that because the server hasn't prepared the file yet.
if i give him Thread.Sleep(100000) i do get the full file, but the file
can be 100Mb and 10sec won't help.

the code is:
//Preparing the file todownload...
//---------------------------------------------------------------------------------------------------------
HttpWebRequest webRequest3 = WebRequest.Create(d1) as
HttpWebRequest;
webRequest3.KeepAlive = true;
webRequest3.Headers.Add("Keep-Alive", "300");
webRequest3.Headers.Add("Accept","text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
webRequest3.Headers.Add("Accept-Language",
"en-us,en;q=0.5");
webRequest3.Headers.Add("Accept-Encoding", "gzip,deflate");
webRequest3.Headers.Add("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");

webRequest3.CookieContainer = cookies;
HttpWebResponse myResponse3 =
(HttpWebResponse)webRequest3.GetResponse();

Thread.Sleep(10000);
Stream ReceiveStream3 = myResponse3.GetResponseStream();

//-----------------------------------------------------------------------------------

//Downloading ....
//--------------------------------------------------------------------------------------
Console.WriteLine("Connecting to download link...");
HttpWebRequest webRequest2 = WebRequest.Create(re) as
HttpWebRequest;
webRequest2.ContentType =
"application/x-www-form-urlencoded";
webRequest2.KeepAlive = true;
webRequest2.CookieContainer = cookies;
HttpWebResponse myResponse2 =
(HttpWebResponse)webRequest2.GetResponse();
Stream ReceiveStream2 = myResponse2.GetResponseStream();
Console.WriteLine("Downloading...");

Common.SaveStreamToFile(@"C:\scrapingtest\file.csv ",
ReceiveStream2);
Console.WriteLine("Done Downloading");

Thanks, Rony

Sep 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: dvsbis | last post by:
does anybody have example of file download using java script thanks dave dvs_bis@sbcglobal.net
3
by: Jerry Camel | last post by:
How do you tell the client how large the file that's being downloaded is? I've seen web sites where the download dialog shows a progress meter. I'm assuming that the server is sending the file...
2
by: marcos | last post by:
sorry, but my english are very bad... how lto dowload visual basic 6.0 from internet?
4
by: Albano Alves | last post by:
Hi! How can I force the file download, for example a .doc? I don't want to open with IE. Thanks. Albano Alves
2
by: comick | last post by:
Hello all, i have a asp.net c# web app 2.0 I have a pdf generation with a third part sw, but i cant download pdf in a new window, from a folder inside my web site. The code i try to use is...
6
by: rony_16 | last post by:
Hi, I have problem with downloading a file using WebRequest and HttpWebResponse. Inorder to download this file i need to call to url that tells to prepare the file for download, and then i call...
1
by: nkamalnath | last post by:
hi, How to dowload a file using javascript.
3
by: Ken Ross | last post by:
Hi all, I have an asp.net 2.0 page that allows users to download a file after clicking the "download now" button. I'm using very similar code to what I've seen on a number of other posts: ...
2
by: nbt725 | last post by:
Dear Sir, Hello ! I want to write a script to allow downloading a file from server, which first asks for the path to store the file and then downloads to user's local machine. Please guide me....
0
by: namrataa | last post by:
how do u download/upload a file in wpf where the data is stored in the database in the binary format. how to link asp.net pages in wpf. please help....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.