Sending GET Request with Custom Headers [Python Code]

To send a GET request with custom HTTP headers, you must provide custom headers in the "Name: Value" format, just like the standard HTTP headers. The format, number, and length of custom headers are unlimited. Custom headers are usually in the X-name form, but this is not required, and you can use your own format when sending custom HTTP headers to the server. In this GET Request with Custom Headers Example, we send a GET request to the ReqBin echo URL with additional data in the custom header. Click Send to execute the GET Request with Custom Headers example online and see the results. The Python code was automatically generated for the GET Request Custom Headers example.
Sending GET Request with Custom Headers [Python Code] Send
GET /echo/get/json HTTP/1.1
Host: reqbin.com
X-Real-IP: 78.110.172.196

Updated: Viewed: 48042 times
Python code for GET Request Custom Headers example

Python code for GET Request Custom Headers Example

This Python code snippet was generated automatically for the GET Request Custom Headers example.
<< Back to the GET Request Custom Headers example

What is HTTP?

Hypertext Transfer Protocol (HTTP) is a network protocol that transfers data between an HTTP client (browser or mobile app) and a server. An HTTP message consists of a request or response line, HTTP headers, and a message body. The client generates a request and sends it to the server. After the server processes this request, it generates a response and sends it back to the client.

What are HTTP Headers?

HTTP headers allow clients to send some information to the server and return some information to the client. HTTP headers are usually invisible to the end-user and are only visible to server soft and network administrators. HTTP headers include a case-insensitive name followed by a colon ":" and its value. Spaces before the value are ignored.

What are Custom Headers?

Custom headers are intended to provide additional information related to the current request or response, or for troubleshooting purposes. Custom header fields usually have an X-field name appended, but this convention has been deprecated due to the inconvenience that some custom fields have become standard.

Custom Header Example
X-Real-IP: 78.110.172.196

What is GET request?

HTTP GET is one of the nine standard HTTP methods. GET is used to request resources from the server using the provided URI. GET requests only receive data and should not change the state of the server.

GET Request with Custom Headers Example

The following is an example of a GET request with Custom Headers to the ReqBin echo URL:

GET Request with Custom Headers Example
GET /echo/get/json HTTP/1.1
Host: reqbin.com
X-Real-IP: 78.110.172.196

The server response to our GET request:

Server Response Example
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 19
      
{"success":"true"}

See also

Generate code snippets for Python and other programming languages

Convert your GET Request Custom Headers request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the Python code generator.