question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EncodeURIComponent within the params option returns a 404 for a GET request

See original GitHub issue

I am fetching a video over the web, convert it to blob/objectURL and return the blob url. The param I am passing to the endpoint URL is a URL itself so I need to encode it to make sure characters that need escaping end up correct. But axios throws me a 404 error in that case. While if I pass the url directly, without encoding it first, status is 200.

This throws a 404:

    return axios(endpoint, { 
        method: 'GET', 
        params: { url: encodeURIComponent(url) },
        responseType: 'arraybuffer',
        headers: new Headers({'Access-Control-Allow-Origin': '*'}) 
      })

This is OK 200:

    return axios(endpoint, { 
        method: 'GET', 
        params: { url: url },
        responseType: 'arraybuffer',
        headers: new Headers({'Access-Control-Allow-Origin': '*'}) 
      })

_BUT_, if I include the encoding directly in the endpoint without using the params option, status is 200, like so:

    return axios(
        `${endpoint}?url=${encodeURIComponent(url)}`, { 
             method: 'GET', 
             responseType: 'arraybuffer',
             headers: new Headers({'Access-Control-Allow-Origin': '*'}) 
           })

Is that normal behavior?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
zzfScarecrowcommented, May 28, 2018

When I use axios.get(url, params),it didn’t encodes at all, but if I encode params manually, it will encodes my params twice

7reactions
puppeteer701commented, Jul 31, 2017

Is there a way to disable encoding of the url?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting a 404 error with parameters which contain periods ...
Try using ajax post method $.ajax({ url: url+ + "/", type: 'POST', data: {data1:encodeURIComponent(text1),data2:encodeURIComponent(text2)}, ...
Read more >
encodeURIComponent() - JavaScript - MDN Web Docs
Parameters. uriComponent. A string to be encoded as a URI component (a path, query string, fragment, etc.) ...
Read more >
Lambda@Edge example functions - Amazon CloudFront
For Node.js functions, each function must call the callback parameter to successfully process a request or return a response.
Read more >
Problem with encoded parameters - MSDN - Microsoft
of these characters using both javascripts 'encodeURIComponent() and ... use thisstring as part of my URL, the URL returns 404 bad request.
Read more >
REST Get - SnapLogic Documentation - Confluence
You can use the REST Get Snap to execute an HTTP Get method on a REST API ... In some cases, the request...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found