Hi all,
VS 2003, windows application that uses Internet. I create an application to merge pdf files downloaded from Internet (which give me one file for one page).
I'm behind a proxy server.
The problem is: when i request a file, the web site creates a temporary file with the page (xxxx.pdf, where pdf are numbers). So these files are also on proxy server and sometimes i have some error because (i think) the page is got from proxy server. How can avoid this problem Turning off the cache of proxy Or from code (c#)
Thx

proxy problem
Ben Morris
Is it possible also not cache file from a particular site...
PS- why do you not add MICROSOFT to your nick, like other Pls not mark your answer as correct...
SaliDM
Now i understand. So this has nothing todo with programming at all, this is a problem of your proxy indeed that will cache the files.
You should contact the administrator to change the caching, this is proxy-side and normally you can't change this.
A suggestion should be that the administrator adds an extra user to the proxy that never grabs files from the cache.
Migrant
Why don't you just retry for 5 times for example it you get an error
Your information is not enough for us to give a good answer, because now i have no idea what code you are using and what kind of exception you get.
erase_ego
KONJIRO
Download class:
...
request = (HttpWebRequest)HttpWebRequest.Create(
new Uri(Url));response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
FileStream fs =
new FileStream(localPath, FileMode.Create); while(true){
int retVal = responseStream.ReadByte(); if(retVal != -1)fs.WriteByte((
byte)retVal); else break;}
fs.Close();
If it's a proxy problem how can i solve and if i want to solve in code, how i can disable cache
codequest
No, this will only improve the connection. Because you don't have to a roundtrip for every byte but grab a full range of bytes.
I should allways try it multiple times since you are using internet. So an timeout can allways happen or other problems.
On wish statement you get an exception and what is the exceptions stacktrace and message
Constantin Mihai - MSFT
This highly depends on the Proxy software that you are using. Please contact you administrator about the proxy issue.
Because i'm not working for Microsoft.I marked its as answered because your problem isn't programming related but is just an proxy issue we can't fix for you. Only your administrator or meybe yourself or anyone who has promission to edit the proxy settings can solve the proxy issue.
We have helped you with the code, improved it a bit but we can't help you with the proxy issue. Sorry for that, but we can't help it because it depends on your proxy software.
alsadykov
I see you are downloading byte for byte, this is not a very great idea because this creates a lot of overhead. Try to use an buffer instread.
Here is your modified code, i haven't test it and just writen it out of the head but it will give you an idea:
int attemped = 0;
while( true )
{
try
{
request = (HttpWebRequest)HttpWebRequest.Create(new Uri(Url));
response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
using( FileStream fs = new FileStream(localPath, FileMode.Create) )
{
byte[] buffer = new byte[ 1024 * 8 ];
int bytesReceived = responseStream.Read( buffer, 0, buffer.Lenght );
while( bytesReceived > 0 )
{
fs.Write( buffer, 0, bytesReceived );
bytesReceived = responseStream.Read( buffer, 0, buffer.Lenght );
}
fs.Close();
}
}
catch( Exception caught )
{
attemped++;
if( attemped < 5 )
{
// Retry.
continue;
}
else
{
// Throw exception because we have tried it 5 times without succes.
throw caught;
}
}
finally
{
if( responseStream != null )
{
responseStream.Close();
}
if( response != null )
{
response.Dispose();
}
}
}
Vipul123
Phlin
Thanks, great idea of buffering (but my file could have very big size!!!...it gives problem )
I don't like solution (try 5 times) because i have not error...the file is correct but content comes from proxy and not from internet...
Craig Thomson
Yes but isn't the same do:
2 reading of 15 or
6 reading of 5
Time to read 15 > Time to read 5
Time to do 2 reading < Time to do 6 reading
EDIT: for the connection, i understand now,,,ok!
I have no exception!!! I download pdf page on single file from a web site (that creates a temporary file in real time named xxx.pdf where xxx are number, and gives me). Sometimes i have already that file on proxy, probably and so the page is wrong!
2 solution: change proxy settings (i can't do it because i'm not expert) or the response must not be cached
Test 007
Thanks...
You could work for Microsoft!
Fretje