I have worked with POST and GET in C# but trying to implement it in C is becoming a bit confusing for me.
I have successfully connected to a socket using 8443 port on my local machine.
Now I am trying to send a POST request, with 3 parameters to the 127.0.0.1:8443/xxxx/xxxAPI
URL.
Usually in GET I can attach the query strings in my URL itself... but in POST I need a message body, contentHeader, Type etc and then my parameters.
I have a custom TCP code in C that helps me connect to the server. After successful connection I am trying to do something like the following pseudo code.... But obviously I don't know what I am doing... Can anyone guide me?
sprintf(szBuff, "POST /xxxx/xxxxxxAPI HTTP/1.1\r\n");
sprintf(contentHeader, "Content-Length: %d\r\n", 20);
send(iSock, szBuff, strlen(szBuff), 0);
send(iSock, "Accept: */*\r\n", 15, 0);
send(iSock, "User-Agent: Mozilla/4.0\r\n", 27, 0);
send(iSock, contentHeader, strlen(contentHeader), 0);
send(iSock, "Accept-Language: en-us\r\n", 26, 0);
send(iSock, "Accept-Encoding: gzip, deflate\r\n", 34, 0);
send(iSock, "Host: ", 6, 0);
send(iSock, "hostname", 8, 0);
send(iSock, "\r\n", 4, 0);
send(iSock, "Content-Type: application/x-www-form-urlencoded\r\n", 50, 0);
send(iSock, "\r\n", 4, 0);
send(iSock, "\r\n", 4, 0);
send(iSock, parameters, strlen(parameters), 0);
send(iSock, "\r\n", 4, 0);
/*if (write(iSock, szBuff, sizeof(szBuff)) == -1)
LogToFile("Error while request being sent to the server");*/