I have a web service which runs with a HttpHandler class. In this class, I inspect the request stream for form / query string parameters. In some circumstances, it seemed as though these parameters weren't getting through. After a bit of digging around, I came across some behaviour I don't quite understand. See below:
// The request contains 'a=1&b=2&c=3'
// TEST ONLY: Read the entire request
string contents;
using (StreamReader sr = new StreamReader(context.Request.InputStream))
{
contents = sr.ReadToEnd();
}
// Here 'contents' is usually correct - containing 'a=1&b=2&c=3'. Sometimes it is empty.
string a = context.Request["a"];
// Here, a = null, regardless of whether the 'contents' variable above is correct
Can anyone explain to me why this might be happening? I'm using a .NET WebClient and UploadDataAsync to perform the request on the client if that makes any difference.
If you need any more information, please let me know.