I am trying to send a large chunk of data over to a HTTP handler. I can\'t send it using GET because of the URL length limit so I decided to POST it instead. The problem is that
Having some code to look at would help diagnose the issue. Have you tried something like this?
jQuery code:
$.post('test.ashx',
{key1: 'value1', key2: 'value2'},
function(){alert('Complete!');});
Then in your ProcessRequest()
method, you should be able to do:
string key1 = context.Request.Form["key1"];
You can also check the request type in the ProcessRequest() method to debug the issue.
if(context.Request.RequestType == "POST")
{
// Request should have been sent successfully
}
else
{
// Request was sent incorrectly somehow
}
POST fields are contained in
HttpContext.Request.Params
To retrieve them you can use
var field = HttpContext.Request.Params["fieldName"];
Faced similar problem. After correcting all issues, there was one more thing I missed in web.config
- to change verb as *
OR GET,POST
. After that everything worked fine.
<httpHandlers>
...
<add verb="*" path="test.ashx" type="Handlers.TestHandler"/>
</httpHandlers>
I was having the same problem, and eventually figured out that setting the content type as "json" was the issue...
contentType: "application/json; charset=utf-8"
That's a line some popular tutorials suggest you to add in the $ajax call, and works well with ASPx WebServices, but for some reason it doesn't for an HttpHandler using POST.
Hard to catch since values in the query string work fine (another technique seen in the web, though it doesn't makes much sense to use POST for that).
I also had the same problem. It was an client/AJAX problem. I had to set the AJAX call request header "ContentType" to
application/x-www-form-urlencoded
to make it work.
The POST data that you are sending to your HTTP Handler must be in querystring format a=b&c=d
. And you can retrieve it on the server-side using Request["a"]
(will return b
), and so on.