Enable Proxy Authentication for normal windows application.

Posted by Lalit on Stack Overflow See other posts from Stack Overflow or by Lalit
Published on 2010-05-20T11:41:26Z Indexed on 2010/05/20 14:00 UTC
Read the original article Hit count: 460

Filed under:
|
|
|

my company's internet works on proxy server with Authentication(i.e. Browser prompts with window for username/password everytime i tried to access any web page).

Now i have some windows application which tries to access internet(like WebPI/Visual Studio 2008 for rss feeds), but as they are unable to popup the the authentication window, they are unable to connect with internet with error:

(407) Proxy Authentication Required

. Here the exception is VS2008, first time it always fails to load rss feeds on startup page, but when i click on the link, it shows authentication window and everything works fine after that.

my question is: How can i configure normal windows application(through app.config/app.manifest file) accessing web to able to show the authentication window or provide default credentials.

For explore this furthor, i have created one console application on VS2008 which tries to serach something on google and display the result on console. Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace WebAccess.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Serach Criteria:");
            string criteria = Console.ReadLine();
            string baseAddress = "http://www.google.com/search?q=";
            string output = "";

            try
            {

                // Create the web request   
                HttpWebRequest request = WebRequest.Create(baseAddress + criteria) as HttpWebRequest;

                // Get response   
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    // Get the response stream   
                    StreamReader reader = new StreamReader(response.GetResponseStream());

                    // Console application output   
                    output = reader.ReadToEnd();
                }

                Console.WriteLine("\nResponse : \n\n{0}", output);
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nError : \n\n{0}", ex.ToString());
            }
        }
    }
}

When running this, It gives error

Enter Serach Criteria:
Lalit

Error :

System.Net.WebException: The remote server returned an error: (407) Proxy Authen
tication Required.
   at System.Net.HttpWebRequest.GetResponse()
   at WebAccess.Test.Program.Main(String[] args) in D:\LK\Docs\VS.NET\WebAccess.
Test\WebAccess.Test\Program.cs:line 26
Press any key to continue . . .

© Stack Overflow or respective owner

Related posts about proxy

Related posts about Windows