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

147
Views
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 answers
Answer question

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 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!