2

I have a Javascript function, that calls window.location.href

Below is the sample example of code.

function xyz () {
    var URL = "https://www.web.com/getNode.jsp?param1=abc|def|ghi|.......";
    window.location.href = URL;
}

Here param1 can accept any nunmber of values. But the problem is if the size of "URL" var is more than 3000 characters, encountering an exception like

500 Internal Server Error.

But my requirement is to pass all the param1 values to the JSP no matter how long param1 is.

Is there any way to solve this Problem?

Can any one please help.

Thanks.

6
  • 6
    I'd consider using a string compressor which is decrypted on the other end, but it might not be enough and that's an X/Y solution. Any possibility of using a POST request instead? Commented Dec 31, 2018 at 10:30
  • 1
    This it's because GET requests size is limited. To send data unlimited, use POST request Commented Dec 31, 2018 at 10:33
  • 7
    Tackle the underlying problem: does the URL really have to be this long, or could you omit some data? Perhaps by storing the data server side and just handing a token around instead. Commented Dec 31, 2018 at 10:35
  • Thanks for the answers. I have no option to send the data using POST method Commented Dec 31, 2018 at 10:42
  • Could you send multiple requests and combine them? Commented Dec 31, 2018 at 11:13

2 Answers 2

4

Let's summarize the facts:

  • You have a requirement to send URLs of unlimited length (quotes: "no matter how long param1 is" and "I have no option to send data using POST")
  • Your server is configured to reject URLs longer than 3000.

The only logical conclusion is: it will not work, no matter how you try. Unless you break (or loosen) the rules.

Any solutions that you may think of will be workarounds which will NOT solve the problem in general, but might be "good enough". You are the only person who can know what "good enough" is - in your context.

Example solutions:

  • reconfigure the server to accept longer URLs
  • pass the actual data in a cookie and only put part of it in the url
  • use a websocket connection or an additional XHR call to send the data ahead of the redirect

Note that all those "solutions" require cheating, as your stated goal remains impossible.

BTW: url shorteners are NOT a solution - they don't do magic, they just redirect people from a short url to a long one. If the target server rejects the longer url, it will still not work.

Sign up to request clarification or add additional context in comments.

Comments

0

you can try change method from GET to POST and add all your params data inside body. Body in POST can contains much more

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.