Sprawdzanie nagłówków HTTP

i18n Checker

Rex Swain's HTTP Viewer

HTTP Header Checker by KeyCDN

Intended audience: users, XHTML/HTML coders (using editors or scripting), script developers (PHP, JSP, etc.), Web project managers, and anyone who needs to know how to check the character encoding used by the HTTP header.

Question

Jak można sprawdzić informacje kodowania znaków wysłaną w nagłówku HTTP dokumentu?

Ważnym jest aby wyraźnie określić kodowanie znaków (charset) dokumentu udostępnionego w sieci. W przeciwnym razie odbiorca może niewłaściwie zinterpretować dokument. Przeglądarka na przykład może wyświetlić znaki na chybił trafił zamiast przedstawić je w formie czytelnej. Jednym sposobem określenia kodowania znaków dokumentu jest umieszczenie tej informacji w parametrze charset nagłówka Content-Type.

In particular, it is important to note that the encoding declared in the HTTP header overrides all in-document encoding declarations in HTML and CSS files.

Answer

Istnieje wiele sposobów sprawdzania dokumentu, w tym sprawdzania nagłówków:

The i18n Checker

The Internationalization Checker tool, developed by the W3C, checks web pages for various internationalisation issues. It also has an information section that summarises key internationalization-related information about a page, such as character encoding and language declarations, etc. That section tells you whether an encoding declaration is used in the HTTP header, and if so, what is the encoding.

The i18n checker tool is particularly useful, since it also shows you other encoding declarations used in the document, and raises a flag if there are differences.

Użyj usług internetowych

Istnieje wiele usług internetowych, które wyświetlają wszystkie nagłówki HTTP i źródło (HTML/XHTML) dokumentu po powrocie z serwera po tym jak wprowadzi się adres dokumentu, którym jesteś zainteresowany:

Uwaga: W3C nie ma powiązań z takimi usługami.

W nagłówkach HTTP szukaj nagłówka Content-Type a w szczególności parametru charset. Np:.

Content-Type: text/html; charset=utf-8

Uwaga: Parametr charset nie musi być obecny. Jest to na tyle właściwe jak długo dokument sam określa swoje własne kodowanie.

Use the developer tools in a browser

Modern desktop browsers usually contain a set of web developer tools, and they can be used to view HTTP headers of a web document and its related resources. Here's how to do it in major browsers.

Chrome, Edge, Firefox, and Opera

  1. Open DevTools by pressing Control+Shift+I or Command+Option+I (Mac).
  2. Click the Network tab. Right now the Network panel is empty.
  3. Reload the page to log some network activity. Each row represents a resource. The top resource is usually the main HTML document.
  4. Click a resource and open the Headers tab to view the HTTP headers.
  5. In the HTTP headers, look for the Content-Type header, and in particular for the charset parameter.

Safari

  1. First ensure that the Develop menu is enabled: choose Safari > Settings, click Advanced, then select “Show Develop menu in menu bar”.
  2. Show page resoueces by clicking Develop > Show Page Resources.
  3. Press Command+Option+0 to show the details sidebar.
  4. Reload the page to log some network activity.
  5. Click a resource from the left sidebar and the HTTP headers will appear in the right sidebar.
  6. In the HTTP headers, look for the Content-Type header, and in particular for the charset parameter.

Użyj telnet lub innego narzędzia komend

Wymaga to trochę ekspertyzy, ale jest łatwiejsze do zautomatyzowania. Inną komendą jest wget (z opcją -S lub-s).

By the way

Niektóre serwery kodują dokumenty w różnych kodach znaków dla różnych klientów. Dzieje się tak np. w Rosji. Wymaga to specjalnej uwagi, ponieważ przeglądarka w systemie Windows czy Mac może wskazywać użycie kodów innych niż te określone przez usługi sieciowe albo W3C Markup Validation Service (które w większości przypadków oparte są na systemach UNIX).