Click here to Skip to main content
14,836,552 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Friends,

I need to create request over HTTPS .Using HTTP its working fine but when I chnage it to HTTPS it throws Time out error .

Please suggest me on this following is my code.

strURL == "";

public static XmlDocument PassXMLRequst(string strURL, XmlDocument objXMLDoc)
//Declare XMLResponse document
XmlDocument XMLResponse = null;

//Declare an HTTP-specific implementation of the WebRequest class.
HttpWebRequest objHttpWebRequest;

//Declare an HTTP-specific implementation of the WebResponse class
HttpWebResponse objHttpWebResponse = null;

//Declare a generic view of a sequence of bytes
Stream objRequestStream = null;
Stream objResponseStream = null;

//Declare XMLReader
XmlTextReader objXMLReader;

//Creates an HttpWebRequest for the specified URL.
objHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);

//---------- Start HttpRequest

//Set HttpWebRequest properties
byte[] bytes;
bytes = System.Text.Encoding.ASCII.GetBytes(objXMLDoc.InnerXml);
objHttpWebRequest.Method = "POST";
objHttpWebRequest.ContentLength = bytes.Length;
objHttpWebRequest.ContentType = "text/xml; encoding='utf-8'";

//Get Stream object
objRequestStream = objHttpWebRequest.GetRequestStream();

//Writes a sequence of bytes to the current stream
objRequestStream.Write(bytes, 0, bytes.Length);

//Close stream

//---------- End HttpRequest

//Sends the HttpWebRequest, and waits for a response.
objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();

//---------- Start HttpResponse
if (objHttpWebResponse.StatusCode == HttpStatusCode.OK)
//Get response stream
objResponseStream = objHttpWebResponse.GetResponseStream();

//Load response stream into XMLReader
objXMLReader = new XmlTextReader(objResponseStream);

//Declare XMLDocument
XmlDocument xmldoc = new XmlDocument();

//Set XMLResponse object returned from XMLReader
XMLResponse = xmldoc;


//Close XMLReader

//Close HttpWebResponse
catch (WebException we)
//TODO: Add custom exception handling
throw new Exception(we.Message);
catch (Exception ex)
throw new Exception(ex.Message);
//Close connections

//Release objects
objXMLReader = null;
objRequestStream = null;
objResponseStream = null;
objHttpWebResponse = null;
objHttpWebRequest = null;

return XMLResponse;

With Regards,
tumbledDown2earth 20-Apr-13 3:01am
Have you enabled https on your webserver (iis) ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900