How to POST data to ASP.NET HttpHandler?

前端 未结 6 732
无人及你
无人及你 2021-02-02 15:58

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

6条回答
  •  执念已碎
    2021-02-02 16:27

    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
    }
    

提交回复
热议问题