I am trying to send an XML request via a HTTPWebRequest however I keep getting a message that the site could not be reached.
However if I turn on Fiddler the request goes through successfully, does anyone know why this might be happening?
This is the code that I am using to send through a request, the request is going to this address http://ift.tt/1BwPMH7
public static string SendRequest(string requestContent, string requestContentType, string requestUrl)
{
try
{
var request = (HttpWebRequest)WebRequest.Create(requestUrl);
byte[] bytes;
bytes = System.Text.Encoding.UTF8.GetBytes(requestContent);
request.ContentType = requestContentType + "; encoding='utf-8'";
request.ContentLength = bytes.Length;
request.Method = "POST";
//request.Timeout = 5000;
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, requestContent.Length);
}
using (var response = (HttpWebResponse)request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
return new StreamReader(responseStream).ReadToEnd();
}
}
}
catch (Exception ex)
{
return ex.ToString();
}
}
No comments:
Post a Comment