My code seems to work fine with standard html (at least getting it) from http sites
(like google.com). But when I change the site to an https site our local proxy server emits 407 errors (indicating that it cannot authenticate the connection). I am using and HttpWebRequest object to perform all the steps.
I have tried Basic, NTLM and Negotiate in the CredentialCache Add method, they all fall over on the https connection.
At this point I am wondering several things:
1) Does the HttpWebRequest.proxy really perform the needed NTLM negotiation?
2) If so, why is it picky about https vs http?
3) Do I need to write my own code to perform the negotiation with the proxy?
4) If so, do I do it in response to the exceptions I am getting at this point, or is there a way to circumvent the exceptions?
Here is a code snippet:
all the required params are passed into the constructor of this object method.
Expand|Select|Wrap|Line Numbers
- public string SendRequest()
- // run the request and return a string response
- {
- string FinalResponse = "";
- string Cookie = "";
- NameValueCollection collHeader = new NameValueCollection();
- HttpWebResponse webresponse;
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
- request.KeepAlive = true;
- request.Timeout = 10000;
- request.Method = "POST";
- request.AllowAutoRedirect = false;
- request.Proxy = WebProxy.GetDefaultProxy();
- string addr = "http://" + ProxyServer + ":" + String.Format("{0:D}", ProxyPort);
- Uri u = new Uri(addr);
- CredentialCache wrCache = new CredentialCache();
- wrCache.Add(u, "Negotiate", System.Net.CredentialCache.DefaultNetworkCredentials);
- request.Proxy.Credentials = wrCache;
- try
- {
- byte[] bytes = Encoding.ASCII.GetBytes(Request);
- request.ContentLength = bytes.Length;
- Stream oStreamOut = request.GetRequestStream();
- oStreamOut.Write(bytes, 0, bytes.Length);
- oStreamOut.Close();
- webresponse = (HttpWebResponse)request.GetResponse();
- if (null == webresponse)
- {
- FinalResponse = "No Response from " + URI;
- }
- else
- {
- Encoding enc = System.Text.Encoding.GetEncoding(1252);
- StreamReader rdr = new StreamReader(webresponse.GetResponseStream(),enc);
- FinalResponse = rdr.ReadToEnd();
- }
- }//End of Try Block
- catch (WebException e)
- {
- // some kind of error..
- if (407 == (int)e.Status)
- {
- }
- throw CatchHttpExceptions(FinalResponse = e.Message);
- }
- catch (System.Exception e)
- {
- throw new Exception(FinalResponse = e.Message);
- }
- finally
- {
- // BaseHttp = null;
- }
- return FinalResponse;
- } //End of SendRequestTo method