简体   繁体   English

请求 URL 太长 HTTP 错误 414。请求 URL 太长

[英]Request URL Too Long HTTP Error 414. The request URL is too long

I am trying to post with ajax post to my c# handler a url with 29376 characters.我正在尝试使用 ajax post 向我的 c# 处理程序发布一个包含 29376 个字符的 url。

I am getting error Request URL Too Long HTTP Error 414. The request URL is too long.我收到错误请求 URL 太长 HTTP 错误 414。请求 URL 太长。 If i am trying to post with a smaller url in the same method the system is working normally.如果我尝试以相同的方法使用较小的 url 发布,则系统正常工作。

what i am missing?我错过了什么?

This is how i post to my handler这就是我发布给我的处理程序的方式

  $.ajax({    
url: "MyHandlers/theHandler.ashx?method=mymethod",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        data: {
            var1: var1,
            var2: var2,
            var3: var3,
            var4: var4,
            var5: var5,
            var6: var6,
            var7: var7,
            var8: var8,
            var9: var9,
            var10: var10,
            var11: var11,
            var12: var12,
            var13: JSON.stringify(var13) //this is the var that is too long
        },
        success: function (result) {

        },
        error: function (result) {

        }
    });

my c# method我的 C# 方法

public string mymethod(int var1, int var2, string var3, string var4, int var5, string var6, string var7, string var8, string var9, string var10, string var11, string var12)
    {
         var jsonString = context.Request.Params["var13"];
    }

you need to specify your ajax request like below:你需要像下面这样指定你的ajax请求:

    $.ajax({
        url: "MyHandlers/theHandler.ashx?method=mymethod",
        contentType: "application/json; charset=utf-8",
        async: false,
        method: "POST",
        data: {
            var1: var1,
            var2: var2,
            var3: var3,
            var4: var4,
            var5: var5,
            var6: var6,
            var7: var7,
            var8: var8,
            var9: var9,
            var10: var10,
            var11: var11,
            var12: var12,
            var13: JSON.stringify(var13) //this is the var that is too long
        },
        dataType: "json"
    });

First - you're not doing POST.首先 - 你不是在做 POST。 You're doing GET as others stated in comments.正如其他人在评论中所说的那样,您正在执行 GET 操作。 414 error means that the URI requested by the client is longer than the server is willing to interpret. 414 错误意味着客户端请求的 URI 比服务器愿意解释的要长。

Most often cause of this error is exactly what you are doing here - sending GET instead of POST.此错误的最常见原因正是您在这里所做的 - 发送 GET 而不是 POST。

Now, what is GET?现在,什么是 GET? GET is a request that is fully send in URI. GET 是在 URI 中完全发送的请求。 Server can interpret the values from URI, for example:服务器可以解释来自 URI 的值,例如:

http://www.example.com?operation=add&value=MyValue

So having more and more values to pass you will end up with too long URL.因此,要传递越来越多的值,您最终会得到太长的 URL。

And what is POST?什么是POST? POST is a request that is not being sent in URI. POST 是未在 URI 中发送的请求。 All the content is sent in http content.所有内容都以http内容发送。 For example: you are sending the content:例如:您正在发送内容:

{
    "FirstName" : "Jack",
    "SecondName": "London"
}

to this address: http://www.example.com到这个地址: http : //www.example.com

So you should here send POST request instead of GET.所以你应该在这里发送 POST 请求而不是 GET。 Just add:只需添加:

type: "POST"

https://api.jquery.com/jquery.post/ https://api.jquery.com/jquery.post/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM