Sign in Registration
ruen

How to send or receive HTTP headers in JavaScript

Typically a server-side language is used to work with headers, but you can also try JavaScript (JS).

js-get-send-http-headers

How to send HTTP request headers

You can send JavaScript headers using Ajax requests. In a pure language, without using libraries, it might look like this:

  var request = new XMLHttpRequest ();
request.open ('GET', document.location, false);
request.setRequestHeader ('Accept', 'text / plain');
request.setRequestHeader ('Content-Type', 'text / plain');
request.setRequestHeader ('Content-Language', 'en-US');
request.send (null);
request.getAllResponseHeaders (). toLowerCase ();  

How to get HTTP response headers

Getting headers in JavaScript is more difficult, since this language works on the client side. But you can send a request to the server using Ajax and get roughly similar headers using the getAllResponseHeaders function. Sample code:

  var request = new XMLHttpRequest ();
request.open ('GET', document.location, false);
request.send (null);
request.getAllResponseHeaders (). toLowerCase ();  

Thus, you can send or receive headers using JavaScript, and not only using server-side languages, like PHP .

Comments (0)
For commenting sign in or register.
Оставить заявку

Последние статьи

Популярные разделы

Eqsash (Инструменты)

Приложение для Android - VK LAST USER ID, отучитель от зависимости и т.д.:
Скачать APK

Amessage (Общение)

Вход в веб-версию
Приложение для Android:
Скачать APK

Поделиться

Подписаться

YouTube

Книги

IT-заметки - Простым языком о самом нужном (HTML, CSS, JavaScript, PHP, базы данных, Drupal, Битрикс, SEO, домены, безопасность и другое), PDF, 500 стр.