3

Trying to GetResponse From a web site;

using System.Text;
using System.Net;
using System.IO;

namespace DutyPharmacy751013
{
class Program
{
    static void Main(string[] args)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        Encoding encoding = Encoding.GetEncoding(response.CharacterSet);

        Stream stream = response.GetResponseStream();
        StreamReader reader = new StreamReader(stream, encoding);
        string responseText= reader.ReadToEnd();
    }
}
}

This code is working on win7 and LAN and on win8 and any of wireless connection but doesn't work on win8 and LAN error: 407 Proxy authentication required. Is there any solution. Thanks.

3
  • do you have web proxy?
    – Damith
    May 7, 2013 at 13:42
  • There is no proxy and Firewall , I m allowed to directly connecting to the internet
    – Sait DURU
    May 7, 2013 at 13:45
  • set request.Proxy as null
    – Damith
    May 7, 2013 at 13:50

2 Answers 2

9

try with adding proxy credentials to request and also give network credentials

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
request.Credentials = new NetworkCredential("username", "pw");

WebProxy webProxy = new WebProxy("http://myproxy.net:8080/", true)
         {
             Credentials = new NetworkCredential("username", "pw"),
             UseDefaultCredentials = false
         };

request.Proxy = webProxy;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

//rest of the code...

Edit

For requests that you create, you can disable automatic proxy detection at the request level by using a null Proxy with your request

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
request.Proxy = null;
//rest of the code
0
2
WebProxy webProxy = new WebProxy("http://myproxy.net:8080/", true)
     {
         UseDefaultCredentials = false,
         Credentials = new NetworkCredential("username", "pw")

     };

Please note Correct sequence to set property {other wise failed for me}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.