locked
httpwebrequest the remote server returned an error 401 unauthorized RRS feed

  • Question

  • Hi all,

    I am facing a strange issue in one of my server..when i am trying to access external live meeting url using Httpwebrequest, i am getting " remote server returned an error 401 unauthorized" error. But the strange thing is, same code is working in my local system.

    code :

    HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(PostingUrl);

    CredentialCache CredMCCache = new CredentialCache();

                myReq.PreAuthenticate = true;

                CredMCCache.Add(new System.Uri(PostingUrl),"Basic",new System.Net.NetworkCredential("username","password")

    myReq.Credentials = CredMCCache;

                myReq.KeepAlive = true;

                myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";

                myReq.Accept = "*/*";

                myReq.Headers.Add("Accept-Language", "en-us");

                myReq.Headers.Add("Accept-Encoding", "gzip, deflate");

    WebProxy proxyObject = new WebProxy("proxy url with port", false);

                myReq.Proxy = proxyObject;

                myReq.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;

    myReq.Method = "GET";

                HttpWebResponse myResp = null;

                    // Get the response from the conference center

                    myResp = (HttpWebResponse)myReq.GetResponse();

    I am getting the error in the above line..any pointers will be helpful

    thanks in advance

    M

    Wednesday, August 1, 2012 2:53 PM