summaryrefslogtreecommitdiff
path: root/libcurl/tests/basic/driver.c
blob: 8e78ba92e3b9a8cc9bb834e2a76aca6a4b14a86f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* file      : tests/basic/driver.c
 * copyright : Copyright (c) 2009-2019 Code Synthesis Tools CC
 * license   : cURL License; see accompanying COPYING file
 */
#include <stdio.h>
#include <assert.h>

#include <curl/curl.h>

/* Usage: argv[0] <URL>
 *
 * Request the specified URL and print the response to stdout.
 */
int
main (int argc, char* argv[])
{
  assert (argc == 2);

  const char* url = argv[1];

  curl_global_init (CURL_GLOBAL_DEFAULT);

  int r = 1;

  CURL* curl = curl_easy_init ();

  if (curl != NULL)
  {
    curl_easy_setopt (curl, CURLOPT_URL, url);

    CURLcode cr = curl_easy_perform (curl);

    if (cr == CURLE_OK)
      r = 0;
    else
      fprintf (stderr,
               "failed to request '%s': %s\n",
               url,
               curl_easy_strerror (cr));

    curl_easy_cleanup (curl);
  }
  else
    fprintf (stderr, "curl_easy_init() failed\n");

  curl_global_cleanup ();
  return r;
}