Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda