proxy problem

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




Answer this question

proxy problem

  • Przemo2

    Can you please share the code that gives problems, because this isn't a code issue i think its just the proxy.

    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.


  • Doug DeBug

    manuel0081 wrote:
    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!


    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.

  • Santig

    Thanks manuel and you are welcome!


  • Rattlerr

    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...



  • karl_otto

    Thanks for the fast reply manuel!

    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();
    }
    }
    }




  • DaveJ4

    manuel0081 wrote:
    Thanks, great idea of buffering (but my file could have very big size!!!...it gives problem )


    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.

    manuel0081 wrote:
    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...


    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


  • Uzzy

     manuel0081 wrote:

    Is it possible also not cache file from a particular site...

    This highly depends on the Proxy software that you are using. Please contact you administrator about the proxy issue.

     manuel0081 wrote:
    PS- why do you not add MICROSOFT to your nick, like other Pls not mark your answer as correct...

    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.


  • Jim McCarthy

    Thanks...

    You could work for Microsoft!



  • ZGutt

    The temporary file is wrong! I think because it's on proxy while i want to get from internet directly...

  • Jeff

    manuel0081 wrote:
    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#)

    What problem are you having All you say is you think you have an error; but you don't say what it is. We can't help you if we don't know the specifics.



  • dazza70

    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



  • robertz2

    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...



  • MCTronix.com

     PJ. van de Sande wrote:

    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.

    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!

     PJ. van de Sande wrote:


    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

     

    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



  • proxy problem