http get and post methods example in c

Get and Post method

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:

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

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

Simple “C” program to create GET Request


Get Request

If you want to learn more about the HTTP, here 10 Free days (up to 200 minutes) HTTP Fundamentals video course for you.


What is the POST method ?

POST method is used to submit data to 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:

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

POST http:// HTTP/1.1


Content-Type: application/xml

Content-Length: 47


Simple “C” program to create POST Request


Post Method


  1. Hi Amlendra, I wanted to do trigger and action to IFTTT, Trigger is if temp >30 switch on AC (trigger parameter 30 OFF) and action parameter 30 ON.

    can you please help me …I am a java developer new to C.

Leave a Reply