2

I have a handler. When I call it with URL that is to say GET method, it works because I get values with my below handler code.

var encodedUrl = HttpUtility.UrlEncode(context.Request.QueryString.ToString());

How can I get values when I use post method which is below from Handler side:

        using (var wb = new WebClient())
        {
            var data = new NameValueCollection();
            data["a"] = "a";
            data["b"] = "b";

            var response = wb.UploadValues("http://localhost:126/Web", "POST", data);
        }
UserStackk
  • 75
  • 1
  • 2
  • 7

1 Answers1

0

When you receive an http response you basically depend on the "Content Type". Depending on this type is that you read it. Here is a reference on this topic:

For instance if you decide to receive an "application/json" response type. You may be able to use this:

From I can see in your sample it looks like you are trying to implement an "application/x-www-form-urlencoded" and the post needs to be formatted accordingly. Here is a sample for that:

  1. http://msdn.microsoft.com/en-us/library/system.net.webclient.headers(v=vs.110).aspx
  2. How are parameters sent in an HTTP POST request?

But there are other options available. I hope this is the answer you were looking for.

Community
  • 1
  • 1
Dalorzo
  • 19,834
  • 7
  • 55
  • 102