Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. WebRequest.GetResponse() = error (407) Proxy Authentication Required

WebRequest.GetResponse() = error (407) Proxy Authentication Required

Scheduled Pinned Locked Moved C#
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abiemann
    wrote on last edited by
    #1

    I'm following this example: http://www.geekpedia.com/tutorial179\_Creating-a-download-manager-in-Csharp.html it seems like a really straight-forward tutorial, however, the line "webResponse = (HttpWebResponse)webRequest.GetResponse();" always gives a (407) Proxy Authentication Required exception. What can I do to make my app pick up the same authentication that Internet Explorer uses ? Note: Internet Explorer LAN settings is set to: Checked "Use automatic configuration script" Address: http://xxxxxxxxxxxxxx.yyyyy.zzzzzzz.net/proxy.pac

    N 1 Reply Last reply
    0
    • A abiemann

      I'm following this example: http://www.geekpedia.com/tutorial179\_Creating-a-download-manager-in-Csharp.html it seems like a really straight-forward tutorial, however, the line "webResponse = (HttpWebResponse)webRequest.GetResponse();" always gives a (407) Proxy Authentication Required exception. What can I do to make my app pick up the same authentication that Internet Explorer uses ? Note: Internet Explorer LAN settings is set to: Checked "Use automatic configuration script" Address: http://xxxxxxxxxxxxxx.yyyyy.zzzzzzz.net/proxy.pac

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Have a look at WebProxy[^] class. After you created the WebProxy instance, supply that to HttpWebRequest.Proxy[^] :)

      Navaneeth How to use google | Ask smart questions

      A E 3 Replies Last reply
      0
      • N N a v a n e e t h

        Have a look at WebProxy[^] class. After you created the WebProxy instance, supply that to HttpWebRequest.Proxy[^] :)

        Navaneeth How to use google | Ask smart questions

        A Offline
        A Offline
        abiemann
        wrote on last edited by
        #3

        GetDefaultProxy() sounds like a dream come true since I don't want the user to have to hassle with copy and pasting their proxy IP and port into my "settings" form. Additionally, I don't want the responsibility of storing their details in an encrypted file. However, GetDefaultProxy() is now antiquated. Also, using UseDefaultCredentials = true doesn't work. Is there an alternate solution to using GetDefaultProxy() ? Maybe reading the registry ?

        A 1 Reply Last reply
        0
        • A abiemann

          GetDefaultProxy() sounds like a dream come true since I don't want the user to have to hassle with copy and pasting their proxy IP and port into my "settings" form. Additionally, I don't want the responsibility of storing their details in an encrypted file. However, GetDefaultProxy() is now antiquated. Also, using UseDefaultCredentials = true doesn't work. Is there an alternate solution to using GetDefaultProxy() ? Maybe reading the registry ?

          A Offline
          A Offline
          abiemann
          wrote on last edited by
          #4

          WebRequest.GetSystemWebProxy() doesn't work either. I still get the 407 error. i.e. webRequest = (HttpWebRequest)WebRequest.Create(strURL); webRequest.Credentials = CredentialCache.DefaultCredentials; IWebProxy wp = WebRequest.GetSystemWebProxy(); webRequest.Proxy = wp;

          1 Reply Last reply
          0
          • N N a v a n e e t h

            Have a look at WebProxy[^] class. After you created the WebProxy instance, supply that to HttpWebRequest.Proxy[^] :)

            Navaneeth How to use google | Ask smart questions

            A Offline
            A Offline
            abiemann
            wrote on last edited by
            #5

            through trial-and-error I finally got it solved. On my journey I've noticed that MANY people have problems with this, so no doubt this code will be copied plenty:

                public string GetWebPage(string strURL)
                {
                    //stores the html returned by the server
                    string strResult = "";
            
                    //build the http request
                    HttpWebRequest webRequest;
                    webRequest = (HttpWebRequest)WebRequest.Create(strURL);
            
                    IWebProxy proxy = WebRequest.GetSystemWebProxy();
                    proxy.Credentials = CredentialCache.DefaultCredentials;
            
                    webRequest.Proxy = proxy;
                    webRequest.Method = "GET";
                    webRequest.UserAgent = "Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+.NET+CLR+1.1.4322)";
                    webRequest.Timeout = -1;
            
                    //initiate contact with the server
                    HttpWebResponse webResponse;
                    webResponse = (HttpWebResponse)webRequest.GetResponse();
            
                    //download the HTML
                    using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))
                    {
                        //read the html
                        strResult = sr.ReadToEnd();
                        // Close and clean up the StreamReader
                        sr.Close();
                    }
            
                    return strResult;
                }
            
            I E 2 Replies Last reply
            0
            • A abiemann

              through trial-and-error I finally got it solved. On my journey I've noticed that MANY people have problems with this, so no doubt this code will be copied plenty:

                  public string GetWebPage(string strURL)
                  {
                      //stores the html returned by the server
                      string strResult = "";
              
                      //build the http request
                      HttpWebRequest webRequest;
                      webRequest = (HttpWebRequest)WebRequest.Create(strURL);
              
                      IWebProxy proxy = WebRequest.GetSystemWebProxy();
                      proxy.Credentials = CredentialCache.DefaultCredentials;
              
                      webRequest.Proxy = proxy;
                      webRequest.Method = "GET";
                      webRequest.UserAgent = "Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+.NET+CLR+1.1.4322)";
                      webRequest.Timeout = -1;
              
                      //initiate contact with the server
                      HttpWebResponse webResponse;
                      webResponse = (HttpWebResponse)webRequest.GetResponse();
              
                      //download the HTML
                      using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))
                      {
                          //read the html
                          strResult = sr.ReadToEnd();
                          // Close and clean up the StreamReader
                          sr.Close();
                      }
              
                      return strResult;
                  }
              
              I Offline
              I Offline
              ishant7890
              wrote on last edited by
              #6

              this is also not working boss.M getting error

              1 Reply Last reply
              0
              • N N a v a n e e t h

                Have a look at WebProxy[^] class. After you created the WebProxy instance, supply that to HttpWebRequest.Proxy[^] :)

                Navaneeth How to use google | Ask smart questions

                E Offline
                E Offline
                ebjean
                wrote on last edited by
                #7

                Hi, not sure if you're still struggling with this. Maybe this could help... I was looking at a solution to call a web service from behind a company firewall, but I didn't want to code any proxy settings nor user credentials in my app. The app should simply use my default IE proxy settings. I'm using .Net 2.0 and here's the C# code to make it work. IWebProxy oProxy = WebRequest.GetSystemWebProxy(); oProxy.Credentials = (System.Net.NetworkCredential)CredentialCache.DefaultCredentials; "your WS stub".Proxy = oProxy; Hope this helps.

                1 Reply Last reply
                0
                • A abiemann

                  through trial-and-error I finally got it solved. On my journey I've noticed that MANY people have problems with this, so no doubt this code will be copied plenty:

                      public string GetWebPage(string strURL)
                      {
                          //stores the html returned by the server
                          string strResult = "";
                  
                          //build the http request
                          HttpWebRequest webRequest;
                          webRequest = (HttpWebRequest)WebRequest.Create(strURL);
                  
                          IWebProxy proxy = WebRequest.GetSystemWebProxy();
                          proxy.Credentials = CredentialCache.DefaultCredentials;
                  
                          webRequest.Proxy = proxy;
                          webRequest.Method = "GET";
                          webRequest.UserAgent = "Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+.NET+CLR+1.1.4322)";
                          webRequest.Timeout = -1;
                  
                          //initiate contact with the server
                          HttpWebResponse webResponse;
                          webResponse = (HttpWebResponse)webRequest.GetResponse();
                  
                          //download the HTML
                          using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))
                          {
                              //read the html
                              strResult = sr.ReadToEnd();
                              // Close and clean up the StreamReader
                              sr.Close();
                          }
                  
                          return strResult;
                      }
                  
                  E Offline
                  E Offline
                  eeidfn
                  wrote on last edited by
                  #8

                  I get the Proxy Authentication only when using NUnit; the same code works fine when invoked in the real environment. Anyway, adding the following lines makes it work in NUnit: IWebProxy proxy = WebRequest.GetSystemWebProxy(); proxy.Credentials = (System.Net.NetworkCredential)CredentialCache.DefaultCredentials; request.Proxy = proxy;

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups