I am attempting to call a RESTful service using an HttpWebRequest object via POST. I am attempting to pass 1 variable with the Request body which contains a url encoded string. I see the request when it hits the server; however, it shows 2 form variables. The first is Form[null] and the second is my variable.
I am attempting to locate the source of this NULL key; however, I cannot. Any ideas on how I may be able to remedy this since it's throwing issues when I attempt to use it with the Nancy web framework for .Net.
Code:
var request = WebRequest.Create("http://localhost:8888/RouteName") as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
var jsonString =
"[\"00000000-0000-0000-000000000001\",\"00000000-0000-0000-000000000002\"]";
var data = new StringBuilder();
data.Append("Keys=" + HttpUtility.UrlEncode(jsonString));
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
request.ContentLength = byteData.Length;
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(byteData, 0, byteData.Length);
}
using (var response = request.GetResponse() as HttpWebResponse)
{
// ends up with a 500 response.
}