简体   繁体   中英

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.

I am getting error Request URL Too Long HTTP Error 414. The request URL is too long. If i am trying to post with a smaller url in the same method the system is working normally.

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

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({
        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. You're doing GET as others stated in comments. 414 error means that the URI requested by the client is longer than the server is willing to interpret.

Most often cause of this error is exactly what you are doing here - sending GET instead of POST.

Now, what is GET? GET is a request that is fully send in URI. Server can interpret the values from URI, for example:

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

So having more and more values to pass you will end up with too long URL.

And what is POST? POST is a request that is not being sent in URI. All the content is sent in http content. For example: you are sending the content:

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

to this address: http://www.example.com

So you should here send POST request instead of GET. Just add:

type: "POST"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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