5

My Android app is making two GET calls to my Server API. In the first one, is this, where parameter code is a 256 char String.

$.getJSON( myServerEndpoint, {
    action: "doStuff1",
    username: $("#username").val(),
    code: my256charString,
    format: "json"
})
.done(function( data ) {
    doStuff2Response(data);  
});

The second one is this, where parameter code is a 5120 char String. Both reach the same server endpoint.

$.getJSON( myServerEndpoint, {
    action: "doStuff2",
    username: $("#username").val(),
    code: my5120CharString,
    format: "json"
})
.done(function( data ) {
    doStuff2Response(data);  
});

When I call both of them from the same device and same user connected to WiFi or most mobile data providers, it works perfectly.

However, when I connect from a Vodafone data connection, the second request never reaches the server. I cannot find any other explanation than that there is a limit on the length of the parameters with Vodafone.

Any ideas or solutions?

Jared Rummler
  • 37,824
  • 19
  • 133
  • 148
  • Are you in interested in a possible solution or just in the explanation of why it doesn't work? – Carlos H Romano Aug 23 '15 at 20:56
  • 1
    Idea! Not an answer! Write a loop which does `$.getJSON( ... code: strLength(i++), format: "json" })` loop 5000 times, and watch for when the hits stop on your server – Reed Spool Aug 30 '15 at 08:50
  • 1
    Oh and then do it 10 more times to see if it's deterministic or not when they stop reaching ;) – Reed Spool Aug 30 '15 at 08:53

2 Answers2

6

OK, so here it goes. First, read this: What is the maximum length of a URL in different browsers?

Yes, there's a limit in the length of the "URL", but someway I don't know how to explain why it is happening only for vodafone. Plus, I don't even know how the request pass through their servers anyways.

As for the solution, you should consider changing from GET request to POST request when the payload is too big.

Community
  • 1
  • 1
Carlos H Romano
  • 616
  • 6
  • 9
0

Quick solution: Base64-encode the code part of the message. Downside: you must decode on the server. This is a standard function in most languages though.

If you're already using Base64 or somesuch cypher, what about Blobs? https://developer.mozilla.org/en-US/docs/Web/API/Blob

chromano's suggestion is spot-on too, just switch to POST and you will definitely get an unlimited Post Body. Downside: Have to JSON.stringify and JSON.parse for yourself, and if you want to expose this URL to a user (say as a link to share) it now can't carry the same information (URL's are GET requests).

Reed Spool
  • 843
  • 7
  • 15