0

I was wondering which library are available for http sending and receiving in C?

I would like to create a program that will load a website. A program that will load Yahoo with a click of a button. A program that will promote me for search term and when I enter it and it will go to the first results of Google and display the information.

Learning C
  • 679
  • 10
  • 27

2 Answers2

5

You can use curl.

There is a demo.

#include <stdio.h>
#include <curl/curl.h>
#include <stdlib.h>
#include <unistd.h>

size_t write_func(void *ptr, size_t size, size_t nmemb, void *userdata)
{
        write(STDOUT_FILENO, ptr, size*nmemb); 
        return size*nmemb;
}

int main(int argv, char *argc[])
{
        CURL *curl;
        if (argv != 2) {
                return 0;
        }
        curl = curl_easy_init();
        if (!curl) {
                fprintf(stderr, "curl_easy_init error");
        }
        curl_easy_setopt(curl, CURLOPT_URL, argc[1]);
        curl_easy_setopt(curl, CURLOPT_HEADER, 1);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_func);
        curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        return 0;
}
xda1001
  • 2,449
  • 16
  • 18
  • Let say I tried to compile this on a windows machine but it give me an error `fatal error: curl/curl.h: No such file or directory compilation terminated.` – Learning C Mar 26 '12 at 02:39
  • That's not a reason to not use it. Give more info, @LearningC. – Mahmoud Al-Qudsi Mar 26 '12 at 02:48
  • 1
    @Learning C, maybe this link will help you.http://stackoverflow.com/questions/197444/building-libcurl-with-ssl-support-on-windows – xda1001 Mar 26 '12 at 02:52
1

Tried boost::asio?

Here are some examples.

Carl
  • 43,122
  • 10
  • 80
  • 104