The Hypertext Transfer Protocol (HTTP) is a stateless application layer protocol for distributed, collaborative, hypermedia information systems.

HTTP use to exchange data over the reliable connection like TCP. In HTTP a client (program) try to establish a connection with other program (Server) to send an HTTP request.

If connection is establish between the server and client then server sends an http response in order to http request.In HTTP mainly GET and POST method are used to send the request to the server.

What is the GET method ?

HTTP get request is generally used to get data from the web-server. It has no side effect and it is not supposed to change anything on server. So GET method is idempotent. It can be executed more than once without any side effects.

Get method issued when you click a hyperlink or when you type an URL in an address bar and hit the enter key.

How to create HTTP GET Request in C ?

The basic parameters of GET request are the path of resource and the Host header.The host header can be the domain name or IP address of the target machine, where we are sending the request.

Suppose there is a service:

http://www.aticleworld.com/2016/04/create-xml-request-in-c-for-server.html

When we prepared a GET request for the above URL then it would be look like this.

GET /2016/04/create-xml-request-in-c-for-server.html HTTP/1.1
Host: www.aticleworld.com

Note: If the server run only single website on a single IP address then you can use IP address as header.

GET /2016/04/create-xml-request-in-c-for-server.html HTTP/1.1
Host: 74.125.28.121

Simple “C” program to create GET Request

OutPut:

Get Request

What is the POST method ?

POST method is use to submit data in the server. Post method is generally used where we want to post a message or submit an information.

POST method is secure followed by GET method because data does not transfer directly in the URL format as in GET method, data send in the message body of request.

There are some extra header which are describe the message body like its length and content type.Using the Get method we can send only ASCII character but using the POST method we can send ASCII as well non ASCII character.

Browser cannot cache or bookmark the POST request data and there is no limitation of the length of request data.

How to create HTTP POST Request in C ?

POST method contain some extra header which describe the content and the length of the request.

Suppose there is a service:

http://www.aticleworld.com/applicationform.svc/getdetail

When we prepared a GET request for the above URL then it would be look like this.

POST http:// 74.125.28.121:80/applicationform.svc/getdetail HTTP/1.1

Host: 74.125.28.121:80

Content-Type: application/xml

Content-Length: 47

<body><name>amlendra</name><age>25</age></body>

Simple “C” program to create POST Request

OutPut:

Post Method