Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
Complex string in Javascript

I want to send my code to this API to compile. But it throws an error cuz there is \n in my string. How can I set this string in my header?

xhr.setRequestHeader('code', 'n = 5\nwhile n > 0:\n   n -= 1\n   print(n)');

OR

xhr.setRequestHeader('code', 
'n = 5
while n > 0:
    n -= 1
    print(n)'
);

This is the error I get :

Uncaught DOMException: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'n = 5
while n > 0:
 n -= 1
 print(n)' is not a valid HTTP header field value.
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are not allowed to use symbol of new line in header value.

However, you can come up with a certain sequence of characters yourself, which the backend will regard as a newline character and automatically replace this sequence with a newline.

But it is better, of course, to transmit such things in the HTTP POST request body, and not in the headers.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda