Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

72
Views
encodeURIComponent cadena de retorno con % en él

¿Por qué cada vez que ejecuto encodeURIComponent('my_url') , obtengo una URL de aspecto extraño como https%3A%2F%2Fr[...] ... ¿Por qué es eso y cómo lo soluciono?

Por cierto, estoy usando Windows.

 function createSharedAccessToken(uri, saName, saKey) { uri = // '...' saName = // '...' saKey = // '...' if (!uri || !saName || !saKey) { throw "Missing required parameter"; } var encoded = encodeURIComponent(uri); var now = new Date(); var week = 60 * 60 * 24 * 7; var ttl = Math.round(now.getTime() / 1000) + week; var signature = encoded + '\n' + ttl; var signatureUTF8 = utf8.encode(signature); var hash = crypto.createHmac('sha256', saKey).update(signatureUTF8).digest('base64'); return 'SharedAccessSignature sr=' + encoded + '&sig=' + encodeURIComponent(hash) + '&se=' + ttl + '&skn=' + saName; }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El tipo de 'url de aspecto extraño' que compartió es exactamente lo que encodeURIComponent está diseñado para devolver.

todos los caracteres excepto AZ az 0-9 - _ . ! ~ * ' ( ) se reemplazan por secuencias de escape.

Por ejemplo, cualquier spaces se convierte en %20 y / se convierte en %2F .

Una URL típica, procesada por encodeURIComponent, podría verse así:

https%3A%2F%2Fstackoverflow.com

Cuando esté listo para mostrar la cadena original, simplemente use decodeURIComponent para revertir el proceso:

decodeYRIComponent('https%3A%2F%2Fstackoverflow.com');

// becomes: https://stackoverflow.com

about 4 years ago · Juan Pablo Isaza Report

0

Está bien explicado aquí, por qué necesitamos codificar la URL

if a user writes Jack & Jill, the text may get encoded as Jack & Jill. Without encodeURIComponent() the ampersand could be interpreted on the server as the start of a new field and jeopardize the integrity of the data.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

Si lo necesitamos en formato legible por humanos, siempre tenemos https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!