Most Common HTTP Headers
Tags: proxy, webscraping, http, beginners
Published: 2022-06-02 07:14:00

A common and repetitive question in the world of web scraping is how to avoid getting blocked by target servers? And, how to increase the quality of retrieved data?

Today, let’s look at one of the useful methods of increasing your chances for smooth data collection – using HTTP headers.


### HTTP headers for web scraping

Of course, there are proven resources and techniques, such as the use of a [proxy](https://oxy.yt/vtsc) or practicing [rotating IP addresses](https://oxy.yt/mtdz) that will help your web scraper to avoid blocks.

However, another sometimes overlooked technique is to use and optimize HTTP headers. This practice will significantly decrease your web scraper’s chances of getting blocked by various data sources, and also ensure that the retrieved data is of high quality. 

Don’t be alarmed if you have little knowledge about HTTP headers, as we covered what [HTTP headers](https://oxy.yt/WtfP) are and discussed how they are connected in the web scraping process on our official blog. 

In this article, we are revealing the 5 most common HTTP headers that need to be used and optimized, and provide you with the reasoning behind it. 

Here is the brief list of the most common HTTP headers:

<table><tbody><tr><td><strong>Header</strong></td><td><strong>Example value</strong></td></tr><tr><td><strong>HTTP header User-Agent</strong></td><td>Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/12.0</td></tr><tr><td><strong>HTTP header Accept-Language</strong></td><td>en-US</td></tr><tr><td><strong>HTTP header Accept-Encoding</strong></td><td>gzip, deflate</td></tr><tr><td><strong>HTTP headers Accept</strong></td><td>text/html</td></tr><tr><td><strong>HTTP header Referer</strong></td><td>http://www.google.com/</td></tr></tbody></table>


**HTTP headers enable both the client and server to transfer further details within the request or response.**


![HTTP headers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tlpv6qv4hciwycn887xr.jpg)


### 1.    HTTP header User-Agent 

The [User-Agent](https://oxy.yt/rtge) request header passes information related to the identification of application type, operating system, software, and its version, and allows for data target to decide what type of HTML layout to use in response i.e. mobile, tablet, or pc. 

<table><tbody><tr><td><strong>User-Agent</strong></td><td>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5)<br>AppleWebKit/605.1.15 (KHTML, like Gecko)<br>Version/12.1.1 Safari/605.1.15</td></tr></tbody></table>

Authenticating the User-Agent request header is a common practice by web servers, and it is the first check that allows data sources to identify suspicious requests. For instance, when web scraping is in process, numerous requests are traveling to the web server, and if User-Agent request headers are identical, it will seem as if it is a bot-like activity. Hence, experienced web scraping punters will manipulate and differentiate User-Agent header strings, which consequently allow portraying multiple organic users’ sessions.

So, when it comes to the User-Agent request header, remember to frequently alter the information this header carries, which will allow you to substantially reduce your odds of getting blocked. 


### 2.    HTTP header Accept-Language

The Accept-Language request header passes information indicating to a web server which languages the client understands, and which particular language is preferred when the web server sends the response back. 

<table><tbody><tr><td><strong>Accept-Language</strong></td><td>en-gb</td></tr></tbody></table>

One thing we need to mention is that this particular header usually comes into play when web servers are unable to identify the preferred language e.g. via URL.

That said, the key with the Accept-Language request header is relevance. It is essential to ensure that set languages are in accordance with the data-target domain and client’s IP location. Simply because, if requests from the same client would appear in multiple languages this would raise suspicions to the web server of bot-like behavior (non-organic request approach), and consequently, they might block the web scraping process. 


### 3.    HTTP header Accept-Encoding

 
The Accept-Encoding request header notifies the web server of what compression algorithm to use when the request is handled. In other words, it states that the required information can be compressed (if the web server can handle it) when being sent out from the web server to the client.

<table><tbody><tr><td><strong>Accept-Encoding</strong></td><td>br, gzip, deflate</td></tr></tbody></table>

However, when optimized it allows saving traffic volume, which is a win-win situation for both you and the web server from the traffic load perspective. You still get the required information (just compressed), and the web server isn’t wasting its resources by transferring a huge load of traffic. 


### 4.    HTTP header Accept

The Accept request header falls into a content negotiation category, and its purpose is to notify the web server on what type of data format can be returned to the client. 

<table><tbody><tr><td><strong>Accept</strong></td><td>test/html,application/xhtml+xml,application/x<br>ml;q=0.9,*/*;q=0.8</td></tr></tbody></table>

It’s as simple as it sounds, but a common hiccup with web scraping is overlooking or forgetting to configure the request header accordingly to the web server’s accepted format. If the Accept request header is configured suitably, it will result in more organic communication between the client and the server, and consequently, decrease the web scraper’s chances of getting blocked.


### 5.    HTTP header Referer

The Referer request header provides the previous web page’s address before the request is sent to the web server. 

<table><tbody><tr><td><strong>Referer</strong></td><td>http://www.google.com/</td></tr></tbody></table>

It might seem that the Referer request header has very little impact when it comes to blocking the scraping process, when in fact, it actually does. Think of a random organic user’s internet usage patterns. This user is quite likely surfing the mighty internet and losing track of hours in a day. Hence, if you want to portray the web scraper’s traffic to seem more organic, simply specify a random website before starting a web scraping session.

The key is not to jump the gun and instead take this rather straightforward step. Hence, remember to always set up the Referer request header, and boost your chances of slipping under anti-scraping measures implemented by web servers.


## Wrapping it up

Now that we have provided the list of common HTTP request headers, you know which web scraping headers to configure, and by doing so, you can increase your web scraper’s chances of a successful and efficient data extraction operation.

It’s safe to state that the more you know about the technical side of web scraping, the more fruitful your web scraping results will be. Use this knowledge wisely, and it’s a given that your web scraper will work more effectively and efficiently!