1

I need to load a pdf by some parameters, which are very long.


URL with parameter example:

example?params=veryLongParams&anotherBigPArams&andTheBiggestParameter


I want to shorten it to something like :

example?params=123csdfskj1k23123jkjkbn12b31


Is there a method to shorten my parameters with js?

tetra master
  • 537
  • 8
  • 13
  • Your question is quite unclear, could you please explain more? You want to upload or download a PDF? Do you own the server? – sjahan Jan 25 '18 at 08:22
  • and in addition to @sjahan's questions - who defined these long parameters and their capturing logic on the server side? – Gonras Karols Jan 25 '18 at 08:23
  • The parameters are dependant on the serverside - if those are the only ones that the server accepts, and you cannot change it - there is nothing you can do about it. – Kamil Solecki Jan 25 '18 at 08:24
  • I'm guessing he's using an online PDF content generator, unless the OP gives us more to work with. – DJDaveMark Jan 25 '18 at 08:51

1 Answers1

1

The short answer is no, not via GET if the URL is too long. How long is too long?

However, the HTTP spec specifies no size limit for POST requests. If the server also accepts POST requests for the same URL endpoint (usually the norm) the following would work (if you or something else can create them):

POST Method Example (MDN Docs)

A simple form using the default application/x-www-form-urlencoded content type:

POST / HTTP/1.1
Host: foo.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 61

params=veryLongParams&anotherBigPArams&andTheBiggestParameter

But depending on what creates the URL, this can be done for you. i.e. an HTML form by specifying method="post".

Sending form data via POST (MDN Docs):

<form action="http://foo.com" method="post">
    <input name="params" value="veryLongParams">
    <input name="anotherBigPArams" value="">
    <input name="andTheBiggestParameter" value="">

    <button type="submit" value="Submit">Submit</button>
</form>
DJDaveMark
  • 2,669
  • 23
  • 35