-1

I'm having an issue with my code consisting on me having a really HUGE url. That "reference" goes on for a long time, and I've tested the same request taking half of those references from it and it worked as intended. Is there a way for me to raise the maximum size of the url?

    const url = `http://localhost:1234/reports/docName.pdf?ID=idOfTheDocument&reference=ref1%20ref2%20ref3%20ref4...`;
    const request = await axios.get(url, {
    auth: {
        username: 'login',
        password: 'password',
        maxContentLength: 100000000,
        maxBodyLength: 1000000000
    },
    responseType: 'arraybuffer',
    });

O know it isn't a good idea, but it's a legacy code I didn't want to refactor.

pliniocf
  • 352
  • 2
  • 8
  • 1
    "*I've tested the same request taking half of those references from it and it worked as intended*" If this is true, then why do you need to "*raise the maximum size of the url*"? This will depend largely on the browser's implementation of their HTTP stack and whether they impose any limit on URLs/query strings, as well as whether the server is capable of handling them. – esqew Jan 21 '22 at 19:21
  • I need to raise the max size of the url because I need that half amount of information I took off. I just did it to assure it was an issue with it's size, but the way it is implemented, that data is necessary. When I said it worked as intended was because it worked for half the amount of information, but the other half was still missing. – pliniocf Jan 21 '22 at 19:26
  • Does this answer your question? [Maximum length of HTTP GET request](https://stackoverflow.com/questions/2659952/maximum-length-of-http-get-request) – esqew Jan 21 '22 at 19:28
  • GET is just not built for transferring large amounts of data in the URL. While not exactly a pure use of http verbs, you could turn your request into a POST and put the large amount of data into the body where you can have as much data as you want. – jfriend00 Jan 21 '22 at 19:36
  • Could you split the request across multiple queries? That is, do one axios.get with half, then another with the other half, then merge the results together? – Patrick Narkinsky Jan 21 '22 at 21:18

1 Answers1

0

I don't know if it's possible to define the maximum length of the url, but you could create an instance of axios to define the base url.

Defining the base url makes necessary to provide only the route name and its parameters.

Check this example:

 const axiosInstance = axios.create({
  baseURL: 'http://localhost:1234'
 })

const route = `reports/docName.pdf? 
ID=idOfTheDocument&reference=ref1%20ref2%20ref3%20ref4...`;

const request = await axiosInstance.get(route , {
 auth: {
    username: 'login',
    password: 'password',
    maxContentLength: 100000000,
    maxBodyLength: 1000000000
 },
 responseType: 'arraybuffer',
});

For more details check this out.

Eduardo
  • 407
  • 1
  • 4
  • 12
  • Defining base url is just a programming convenience. axios will still be making the giant url and will still run into browser limits. – jfriend00 Jan 21 '22 at 19:34