6 Replies - 3117 Views - Last Post: 03 May 2010 - 05:30 AM Rate Topic: -----

#1 djlakshmi   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 72
  • Joined: 22-March 10

Exception while Login using httpwebrequest

Posted 30 April 2010 - 03:34 AM

hello all,
i just searched via google and found a set of codes to login to a web site using httpwebrequest. but whenever i tried using the codes i got the very same exception that

The remote server returned an error: (407) Proxy Authentication Required.

one of the sample code i ve used
ArrayList theQueryData = new ArrayList();
   
            theQueryData.Add(String.Format("{0}={1}", "username", HttpUtility.UrlEncode("test")));
            theQueryData.Add(String.Format("{0}={1}", "password", HttpUtility.UrlEncode("test")));
            string Parameters = String.Join("&", (String[])theQueryData.ToArray(typeof(string)));
            Uri url = new Uri("https://www.test.com/test/testlogin.cfm");
            HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);
        
            webReq.ContentType = "application/x-www-form-urlencoded";
            webReq.Method = "POST";
            webReq.AllowWriteStreamBuffering = true;
            webReq.AllowAutoRedirect = false;
            webReq.Credentials = CredentialCache.DefaultCredentials;
            webReq.CookieContainer = container;
            webReq.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
            webReq.KeepAlive = true;
            // We write the parameters into the request 
            StreamWriter sw = new StreamWriter(webReq.GetRequestStream());
            sw.Write(Parameters);
            sw.Close();
            HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
            response.Cookies = webReq.CookieContainer.GetCookies(webReq.RequestUri); 


what should i do to get it work..
need help.

Is This A Good Question/Topic? 0
  • +

Replies To: Exception while Login using httpwebrequest

#2 RudiVisser   User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,566
  • Joined: 05-June 09

Re: Exception while Login using httpwebrequest

Posted 01 May 2010 - 04:01 AM

That's an error from the remote server.

Could you post the actual URL that you're trying to retrieve so that we/I can try running your code?
Was This Post Helpful? 0
  • +
  • -

#3 batesy3k   User is offline

  • D.I.C Regular

Reputation: 41
  • View blog
  • Posts: 299
  • Joined: 10-September 09

Re: Exception while Login using httpwebrequest

Posted 01 May 2010 - 12:27 PM

When I used to get this error, it was because my computer was behind a network proxy. To get round this I used the WebProxy class like so:
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);
WebProxy proxyObj = new WebProxy("address:port"); // e.g. someserver:8080
proxyObj.Credentials = CredentialCache.DefaultCredentials;

// set the webReq proxy here
webReq.Proxy = proxyObj;



Hope this points you in the right direction
Was This Post Helpful? 0
  • +
  • -

#4 djlakshmi   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 72
  • Joined: 22-March 10

Re: Exception while Login using httpwebrequest

Posted 02 May 2010 - 10:37 PM

View PostRudiVisser, on 01 May 2010 - 03:01 AM, said:

That's an error from the remote server.

Could you post the actual URL that you're trying to retrieve so that we/I can try running your code?


sorry sir,

i cant specify the exact url here bcoz im a student and doing a project in a concern. so i cant let u know the url.
Was This Post Helpful? 0
  • +
  • -

#5 djlakshmi   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 72
  • Joined: 22-March 10

Re: Exception while Login using httpwebrequest

Posted 03 May 2010 - 03:13 AM

Thanks for replying RudiVisser, batesy3k

but whatever i tried it gives the same exception only.. i ve tried a simple file download from a web page for which too it returns the same exception that

" WebException was handled
The remote server returned an error: (407) Proxy Authentication Required."

i used the sample code
private void button1_Click(object sender, EventArgs e)
        {
            WebClient wc = new WebClient();

            wc.DownloadFile(textBox1.Text,textBox2.Text);


        }



pls do help. i dnt know why im getting this for every thing im trying.. is it a prob with my net connection?
Was This Post Helpful? 0
  • +
  • -

#6 RudiVisser   User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,566
  • Joined: 05-June 09

Re: Exception while Login using httpwebrequest

Posted 03 May 2010 - 04:40 AM

Well could you PM me the URL? If I (or somebody else external) can make it work, then we know that it *is* at your end. If I get the same error, it's the server. :)
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: Exception while Login using httpwebrequest

Posted 03 May 2010 - 05:30 AM

Might I suggest searching Google and reading?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1