0

I've set up a page to do an HTTP Post with a Json serialized generic list, to a different page in ASP.net. When it goes to the new page though, I can't seem to find the body of the HTTP Post.

This is the method for the post:

    public static void SendHttpPost(string json)
    {            
        var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:57102/Post.aspx");

        httpWebRequest.ContentType = "text/json";
        httpWebRequest.Method = "POST";
        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            streamWriter.Write(json);
            streamWriter.Flush();
            streamWriter.Close();

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
            }
        }
    }

Although this is the first time I've done this, I presumed you would be able to access the Json using Request.Form or similar, but Request.Form is empty. I've had a good look at the VS degugger and can't see it anywhere in the Request object, but the content length is 68000 bytes, so I'm sure it's in there somewhere!

Can anyone point me in the right direction please? Many thanks

2
  • If i understand well, what you send to the page "/Post.aspx" should be in Request.InputStream (gist.github.com/leggetter/769688). Is that what you are looking for ? Commented May 25, 2013 at 10:45
  • That is exactly what I was looking for thanks - perfect. If you add that as an answer, then I'll mark it as correct. Commented May 25, 2013 at 10:54

1 Answer 1

1

You can retrieve the Request Body using Request.InputStream as shown here : gist.github.com/leggetter/769688 !

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.