Super Agent Coding Problem

I am trying to make an API call with a superagent, but it encodes my api key, which is rejected.

get(url).query({ key: 'Fmjtd%7Cluu').end(function(err, res) { 

The key is sent as

 Fmjtd%257Cluu 

Any ideas how to prevent this use of a super agent? If I make it part of the url part, that’s fine, but I would like to pass it as request data, if possible.

+4
source share
1 answer

I am not familiar with SuperAgent, but here are the options I would take to solve the problem.

  • Escape the key. Try "Fmjtd \% 7Cluu"

  • Since SuperAgent seems to be using "encodeURIComponent" to convert the key to make it safe for the HTTP transport, you can first "decodingURIComponent" before passing it. However, it is entirely possible that this will break SuperAgent (as they probably have a good reason for encoding URI components in the first place).

  • Submit a bug report and ask the maintainer to create the correct fix instead of the hacks I suggest above

0
source

Source: https://habr.com/ru/post/1482775/


All Articles