none
(407) Proxy Authentication Required. RRS feed

  • Question

  • Hi,

    I am trying to write a winform application that needs to access internet with or without proxy.

    the code is:

    string rssURL = "http://msdn.microsoft.com/rss.xml";

    // Begin the WebRequest to the desired RSS Feed

    System.Net.WebRequest myRequest = System.Net.WebRequest.Create(rssURL);

    System.Net.WebResponse myResponse = myRequest.GetResponse();

    Resuts:

    1. without proxy like home, the above works well.

    2. with proxy like company, the above return error at the last line.

    i searched the issue online, a lot people talked about this, but i can not find a working solution yet.

    Any help is appreciated. -Dale

    Monday, March 27, 2006 6:50 PM

Answers

  • Hi Dale,

    You're going to have to provide the credentials necessary to get through the proxy.
    I.E.
    string rssURL = "http://msdn.microsoft.com/rss.xml";

    System.Net.WebProxy rssProxy = new System.Net.WebProxy("ISA_SERVER", PORT_NUMBER);
    rssProxy.Credentials =
    new System.Net.NetworkCredential("myusername", "mypassword", "mydomain");

    // bypass the proxy on local network
    rssProxy.BypassProxyOnLocal = true;
    System.Net.
    GlobalProxySelection.Select = rssProxy;
    System.Net.
    WebRequest myRequest = System.Net.WebRequest.Create(rssURL);
    // assign the proxy to the request
    myRequest.Proxy = rssProxy;

    System.Net.
    WebResponse myResponse = myRequest.GetResponse();

    Look at the Network Credential class.http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemnetnetworkcredentialclasstopic.asp?frame=true

    and the webProxy class http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemNetWebProxyClassTopic.asp?frame=true

    Monday, March 27, 2006 7:31 PM
  • You can specify a proxy for you request with setting the Proxy property. Here is an example:


    System.Net.WebRequest myRequest = System.Net.WebRequest.Create( rssURL );

    System.Net.WebProxy proxy = new System.Net.WebProxy();
    proxy.Address = new Uri( "http://10.0.0.1" );
    proxy.Credentials = new System.Net.NetworkCredential( "myusername", "mypassword" );

     

    Monday, March 27, 2006 7:35 PM
    Moderator
  • try this:

    rssProxy.Credentials = (System.Net.NetworkCredential)System.Net.CredentialCache.DefaultCredentials;

    Monday, March 27, 2006 8:17 PM

All replies

  • Hi Dale,

    You're going to have to provide the credentials necessary to get through the proxy.
    I.E.
    string rssURL = "http://msdn.microsoft.com/rss.xml";

    System.Net.WebProxy rssProxy = new System.Net.WebProxy("ISA_SERVER", PORT_NUMBER);
    rssProxy.Credentials =
    new System.Net.NetworkCredential("myusername", "mypassword", "mydomain");

    // bypass the proxy on local network
    rssProxy.BypassProxyOnLocal = true;
    System.Net.
    GlobalProxySelection.Select = rssProxy;
    System.Net.
    WebRequest myRequest = System.Net.WebRequest.Create(rssURL);
    // assign the proxy to the request
    myRequest.Proxy = rssProxy;

    System.Net.
    WebResponse myResponse = myRequest.GetResponse();

    Look at the Network Credential class.http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemnetnetworkcredentialclasstopic.asp?frame=true

    and the webProxy class http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemNetWebProxyClassTopic.asp?frame=true

    Monday, March 27, 2006 7:31 PM
  • You can specify a proxy for you request with setting the Proxy property. Here is an example:


    System.Net.WebRequest myRequest = System.Net.WebRequest.Create( rssURL );

    System.Net.WebProxy proxy = new System.Net.WebProxy();
    proxy.Address = new Uri( "http://10.0.0.1" );
    proxy.Credentials = new System.Net.NetworkCredential( "myusername", "mypassword" );

     

    Monday, March 27, 2006 7:35 PM
    Moderator
  • somehow, this does not work.

    But the one from crock does work. There is another issue raised by this solution: if I give this winform application to my coworkers, it will not work since I can not embedded everyone's username and password into the application.

    Is there any general solution?

    Thanks.

    Monday, March 27, 2006 8:07 PM
  • try this:

    rssProxy.Credentials = (System.Net.NetworkCredential)System.Net.CredentialCache.DefaultCredentials;

    Monday, March 27, 2006 8:17 PM
  • this works. thanks

    sorry one more last issue.

    is there a way to make the following line for every company?

     

    System.Net.WebProxy rssProxy = new System.Net.WebProxy("servername", port);

     

    right now only my coworkers within my company can use the application. want to see if public can use it?

    thanks again.

    Monday, March 27, 2006 9:39 PM
  • Tuesday, March 28, 2006 1:38 AM