Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以不同的方式处理帖子_C#_Asp.net_Json_Post_Handler - Fatal编程技术网

C# 以不同的方式处理帖子

C# 以不同的方式处理帖子,c#,asp.net,json,post,handler,C#,Asp.net,Json,Post,Handler,我目前在我的C#处理程序(.ashx)中使用context.Request.QueryString,因为直到现在我只需要处理GET POST 但是如果通过POST方法向我发送一个JSON对象呢?我知道我应该反序列化发送的内容,但我的观点是-我如何知道发送源是否发送了POST或GET 为什么??因为我想将处理程序拆分为POST相关函数(通常需要安全性的东西)和更原始的GET相关函数(检索公共信息等) 如果重要的话,我的代码现在看起来是这样的(它还没有准备好正确处理帖子) 您可以访问context.

我目前在我的C#处理程序(.ashx)中使用context.Request.QueryString,因为直到现在我只需要处理GET POST

但是如果通过POST方法向我发送一个JSON对象呢?我知道我应该反序列化发送的内容,但我的观点是-我如何知道发送源是否发送了POST或GET

为什么??因为我想将处理程序拆分为POST相关函数(通常需要安全性的东西)和更原始的GET相关函数(检索公共信息等)

如果重要的话,我的代码现在看起来是这样的(它还没有准备好正确处理帖子)


您可以访问
context.Request
,因此您可以简单地使用its来确定它是POST、GET还是其他内容。

您可以使用
Request.Form[参数]
进行POST。查看相关帖子:

要检查请求是POST还是GET,可以使用
HttpContext.Current.request.HttpMethod
(from)

public void ProcessRequest (HttpContext context) {
    context.Response.ContentType = "application/json";
    JavaScriptSerializer jss = new JavaScriptSerializer();

    // Wanna know POST was used here, so I can deserialize the sent JSON data
    // ----

    // Handling GET here, good and working
    if (context.Request.QueryString["aname"] != null
        && context.Request.QueryString["type"] != null)
    {
         string adminName = context.Request.QueryString["aname"];
         if(adminName == "test") { // Return some JSON object }
    }
}