You can do your own communication library to talk with your service, but it is complex and you should conform to a lot of RFC's.

There is another way to do the work, you can use an already written (and tested library), you can use the libcurl library!

curl-refined

From the wikipedia:
"libcurl is a free client-side URL transfer library, supporting FTP, FTPS, Gopher, HTTP, HTTPS, SCP, SFTP, TFTP, Telnet, DICT, the file URI scheme, LDAP, LDAPS, IMAP, POP3, SMTP and RTSP. The library supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, Kerberos, HTTP form based upload, proxies, cookies, user-plus-password authentication, file transfer resume, and HTTP proxy tunneling.
The libcurl library is portable. It builds and works identically on several platforms, including Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, HPUX, IRIX, AIX, Tru64, Linux, UnixWare, HURD, Windows, Symbian, AmigaOS, OS/2, BeOS, Mac OS X, Apple iOS, Android, Ultrix, QNX Neutrino, BlackBerry Tablet OS and BlackBerry 10,[3] OpenVMS, RISC OS, Novell NetWare, DOS and more."

 

Imagine you want to send data to a php page  (for example http://www.your_domain.com/insert_data.php) that stores this data int a mysql database, And the php script accept data as (_GET) variables, for example an ID (int) and a string.

One of the examples provided by the official site is very simple and do the work with a few changes:

 

/***************************************************************************

 *                                  _   _ ____  _

 *  Project                     ___| | | |  _ \| |

 *                             / __| | | | |_) | |

 *                            | (__| |_| |  _ <| |___

 *                             \___|\___/|_| \_\_____|

 *

 * Copyright (C) 1998 – 2013, Daniel Stenberg, <daniel@haxx.se>, et al.

 *

 * This software is licensed as described in the file COPYING, which

 * you should have received as part of this distribution. The terms

 * are also available at http://curl.haxx.se/docs/copyright.html.

 *

 * You may opt to use, copy, modify, merge, publish, distribute and/or sell

 * copies of the Software, and permit persons to whom the Software is

 * furnished to do so, under the terms of the COPYING file.

 *

 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY

 * KIND, either express or implied.

 *

 ***************************************************************************/

#include <stdio.h>

#include <curl/curl.h>

#define MYURL "http://www.your_damin.com/insert_data.php?ID=%d&name=%s"

 

int main(int argc, char **argv)

{

    CURL *curl;

    CURLcode res;

    char destination[400];

 

    if (argc!=3) {

        usage(argv[0]);

        exit(EXIT_FAILURE);

    }

    

    sprintf(destination, MYURL, atoi(argv[1]), argv[2]);

    curl = curl_easy_init();

    if(curl) {

        curl_easy_setopt(curl, CURLOPT_URL, destination);

        /* example.com is redirected, so we tell libcurl to follow redirection */

        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

        

        /* Perform the request, res will get the return code */

        res = curl_easy_perform(curl);

        /* Check for errors */

        if(res != CURLE_OK)

            fprintf(stderr, "curl_easy_perform() failed: %s\n",

                    curl_easy_strerror(res));

        

        /* always cleanup */

        curl_easy_cleanup(curl);

    }

    return 0;

}

 

void usage(char *arg)

{

    printf("Usage: ./%s <ID> <name>\n");

}

 

The first time I used the above code with my web site I encountered the first problem….

The provider of the hosting of my web site checks for the user agent:

so I had to set up the user agent…. just one line of code

 

int main(int argc, char **argv)

{

    CURL *curl;

    CURLcode res;

    char destination[400];

 

    if (argc!=3) {

        usage(argv[0]);

        exit(EXIT_FAILURE);

    }

    

    sprintf(destination, MYURL, atoi(argv[1]), argv[2]);

    curl = curl_easy_init();

    if(curl) {

        curl_easy_setopt(curl, CURLOPT_URL, destination);

        curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5");

        /* example.com is redirected, so we tell libcurl to follow redirection */

        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

        

        /* Perform the request, res will get the return code */

        res = curl_easy_perform(curl);

        /* Check for errors */

        if(res != CURLE_OK)

            fprintf(stderr, "curl_easy_perform() failed: %s\n",

                    curl_easy_strerror(res));

        

        /* always cleanup */

        curl_easy_cleanup(curl);

    }

    return 0;

}

 

Then I tried again, but the code didn't work again.. The site I was using, had a basic authentication so I couldn't access my php page :

"HTTP  Basic  authentication. This is the default choice, and the only method that is in wide-spread use and supported virtually everywhere. This sends the user name and  pass-word password word over the network in plain text, easily captured by others."

curl povides an option to set username and password with a little work, I had to add two lines of code

  curl_easy_setopt(curl, CURLOPT_USERPWD, "yourusername:yourpassword");

  curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST);

 

 

and this was the final result:

int main(int argc, char **argv)

{

    CURL *curl;

    CURLcode res;

    char destination[400];

 

    if (argc!=3) {

        usage(argv[0]);

        exit(EXIT_FAILURE);

    }

    

    sprintf(destination, MYURL, atoi(argv[1]), argv[2]);

    curl = curl_easy_init();

    if(curl) {

        curl_easy_setopt(curl, CURLOPT_URL, destination);

        curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5");

        curl_easy_setopt(curl, CURLOPT_USERPWD, "yourusername:yourpassword");

        curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST);

        /* example.com is redirected, so we tell libcurl to follow redirection */

        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

        

        /* Perform the request, res will get the return code */

        res = curl_easy_perform(curl);

        /* Check for errors */

        if(res != CURLE_OK)

            fprintf(stderr, "curl_easy_perform() failed: %s\n",

                    curl_easy_strerror(res));

        

        /* always cleanup */

        curl_easy_cleanup(curl);

    }

    return 0;

}

 

to compile, save the file as simple.c and then issue the following command:

Gg1