HTTPWebResponse returning no content
- by Richard Yale
Our company works with another company called iMatrix and they have an API for creating our own forms. They have confirmed that our request is hitting their servers but a response is supposed to come back in 1 of a few ways determined by a parameter. I'm getting a 200 OK response back but no content and a content-length of 0 in the response header.
here is the url:
https://secure4.office2office.com/designcenter/api/imx_api_call.asp
I'm using this class:
namespace WebSumit
{
public enum MethodType
{
POST = 0,
GET = 1
}
public class WebSumitter
{
public WebSumitter()
{
}
public string Submit(string URL, Dictionary<string, string> Parameters, MethodType Method)
{
StringBuilder _Content = new StringBuilder();
string _ParametersString = "";
// Prepare Parameters String
foreach (KeyValuePair<string, string> _Parameter in Parameters)
{
_ParametersString = _ParametersString + (_ParametersString != "" ? "&" : "") + string.Format("{0}={1}", _Parameter.Key, _Parameter.Value);
}
// Initialize Web Request
HttpWebRequest _Request = (HttpWebRequest)WebRequest.Create(URL);
// Request Method
_Request.Method = Method == MethodType.POST ? "POST" : (Method == MethodType.GET ? "GET" : "");
_Request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Win32)";
// Send Request
using (StreamWriter _Writer = new StreamWriter(_Request.GetRequestStream(), Encoding.UTF8))
{
_Writer.Write(_ParametersString);
}
// Initialize Web Response
HttpWebResponse _Response = (HttpWebResponse)_Request.GetResponse();
// Get Response
using (StreamReader _Reader = new StreamReader(_Response.GetResponseStream(), Encoding.UTF8))
{
_Content.Append(_Reader.ReadToEnd());
}
return _Content.ToString();
}
}
}
I cannot post the actual parameters because they are to the live system, but can you look at this code and see if there is anything that is missing?
Thanks!