ieplugin
ieplugin

Reputation: 681

What's the most efficient way to get source code of web page in C?

In PHP I can do it as simple as :

file_get_contents('http://stackoverflow.com/questions/ask');

What's the shortest code to do the same in C?

UPDATE

When I compile the sample with curl, got errors like this:

unresolved external symbol __imp__curl_easy_cleanup referenced in function _main 

Upvotes: 5

Views: 490

Answers (3)

Vanni Totaro
Vanni Totaro

Reputation: 5491

I should have commented the Richard Harrison good answer, but I have not 50 reputations points yet, so I put here as an answer my hint to ieplugin for compiling the code:

On Ubuntu 10.04 (and supposing you named the source file getpage.c):

sudo apt-get install libcurl4-dev
gcc getpage.c -lcurl -o getpage

Upvotes: 1

Richard Harrison
Richard Harrison

Reputation: 19403

Use libcurl, refer to their example C snippets

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

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se");
    res = curl_easy_perform(curl);

    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }
  return 0;
}

Upvotes: 10

David Sykes
David Sykes

Reputation: 49882

Try the libcurl C interface

Upvotes: 2

Related Questions