Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format of an HTTP get request

I'm writing an HTTP server (for the sole purpose of educating myself).

A typical GET request seems to be this:

GET /?a=1&b=2 HTTP/1.1 
Host: localhost    
User-Agent: my browser details
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8    
Accept-Language: en-gb,en;q=0.5    
Accept-Encoding: gzip, deflate    
Connection: keep-alive

The only place I can see the variables being sent is in the first line. It would be easy enough to write a regex to get the variables and their contents, but I'm wondering if there is an easier way. I ask because I always assumed that the idea of url?first_variable=first_value&second_variable=second_value was part of the protocol, and special in some way. However, as far as I can see, this isn't the case, and I could equally just do url$first_variable-first_value?second_variable-second_value or something.

like image 445
rlms Avatar asked Jan 17 '14 21:01

rlms


People also ask

What is the format of HTTP request message?

HTTP requests are messages sent by the client to initiate an action on the server. Their start-line contain three elements: An HTTP method, a verb (like GET , PUT or POST ) or a noun (like HEAD or OPTIONS ), that describes the action to be performed.

How does HTTP GET request work?

How Do HTTP Requests Work? HTTP requests work as the intermediary transportation method between a client/application and a server. The client submits an HTTP request to the server, and after internalizing the message, the server sends back a response. The response contains status information about the request.

What is HTTP GET?

HTTP GET: The Hypertext Transfer Protocol(HTTP) Get method is mainly used at the client (Browser) side to send a request to a specified server to get certain data or resources. Using this method the server should only let us receive the data and not change its state.

What is HTTP request example?

HTTP works as a request-response protocol between a client and server. Example: A client (browser) sends an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and may also contain the requested content.


1 Answers

What you are referring to is the Query portion of a URL, as defined in section 3.4 of the URL specification, and allowed by section 3.2 of the HTTP specification.

Passing parameters in the requested URL is not the only way to send parameters in an HTTP request, though. Another option is to use the application/x-www-form-urlencoded or multipart/form-data Content Type in a POST request, as defined by section 17.13.4 of the HTML 4.01 specification and section 4.10.22 of the HTML5 specification, eg:

POST / HTTP/1.1 
Host: localhost    
User-Agent: my browser details
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8    
Accept-Language: en-gb,en;q=0.5    
Accept-Encoding: gzip, deflate    
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 7

a=1&b=2
POST / HTTP/1.1 
Host: localhost    
User-Agent: my browser details
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8    
Accept-Language: en-gb,en;q=0.5    
Accept-Encoding: gzip, deflate    
Connection: keep-alive
Content-Type: multipart/form-data; boundary=myboundary

--myboundary
Content-Disposition: form-data; name="a"

1
--myboundary
Content-Disposition: form-data; name="b"

2
--myboundary--
like image 64
Remy Lebeau Avatar answered Sep 28 '22 13:09

Remy Lebeau