Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to POST data to ASP.NET HttpHandler?

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 I can't get at the values. context.Request.Form shows that it has 0 items. So is there a way that I can POST data to a HttpHandler?

like image 365
Ali Kazmi Avatar asked May 26 '09 05:05

Ali Kazmi


People also ask

What is the difference between Httpmodule and HTTP handler?

HTTP handler is the process that runs in response to a request made to an ASP.NET Web application. HTTP modules let you examine incoming and outgoing requests and take action based on the request.

What is HTTP handler in ASP.NET MVC?

HTTPHandler is a low level request and response API in ASP.Net for injecting pre-processing logic to the pipeline based on file extensions and verbs. An HTTPhandler may be defined as an end point that is executed in response to a request and is used to handle specific requests based on extensions.


2 Answers

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
}
like image 156
Dan Herbert Avatar answered Sep 28 '22 19:09

Dan Herbert


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.

like image 44
splattne Avatar answered Sep 28 '22 21:09

splattne