PHP code for GET Request ExampleThis PHP code snippet was generated automatically for the GET Request example.
<< Back to the GET Request example
What is HTTP?
The Hypertext Transfer Protocol (HTTP) is the core of the World Wide Web and powers websites and mobile applications. The HTTP is designed to transfer information between networked devices and provides a framework for client/server communication. HTTP works as a request/response protocol between client and server. For example, a browser (client) sends an HTTP GET request to a web server (server); the server then returns the response to the browser. The HTTP request contains the HTTP method (mostly GET), target URL, HTTP request headers, and additional URL parameters. The HTTP response includes information on the request's status (mostly 200), the requested content (HTML, JSON, image, etc.), and optional HTTP headers on how to interpret this content. All modern programming languages natively support HTTP, including PHP.
What is HTTP GET request?
HTTP GET request method is used to retrieve data from a specified URL. The GET is the most popular HTTP request method. GET requests should only receive data and should not affect the state of the server.
HTTP GET Request Format
The GET request consists of the request-line and HTTP headers section. The GET request-line begins with an HTTP method token, followed by the request URI and the protocol version, ending with CRLF. Space characters separate the elements. Below is an example of a GET request to the ReqBin echo server and the auto-generated PHP code.
Some notes on HTTP GET Requests
- GET request method is used to get a resource from the server
- GET requests cannot have a message body, but you still can send data to the server using the URL parameters
- GET requests should only receive data. If you want to change data on the server, use POST, PUT, PATCH, or DELETE methods
- GET method is defined as idempotent, which means that multiple identical GET requests should have the same effect as a single request
HTTP GET Request Examples
Example of getting HTML page from ReqBin echo URL with PHP.
Example of getting JSON data from ReqBin echo URL with PHP.
Example of getting XML data from ReqBin echo URL with PHP.