curl / Mailing Lists / curl-users / Single Mail

curl-users

libcurl newbie question on output

From: Lonnie Cumberland <lonnie_at_outstep.com>
Date: Sat, 14 Apr 2018 20:01:30 -0400

Hello All,

I am new to using libcurl and have been able to compile up a number of
examples with no problems.

As an example:

---------------------------------

*/***************************************************************************
 * _ _ ____ _
 * Project ___| | | | _ \| |
 * / __| | | | |_) | |
 * | (__| |_| | _ <| |___
 * \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel_at_haxx.se
<daniel_at_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 https://curl.haxx.se/docs/copyright.html
<https://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.
 *
 ***************************************************************************/
**/* <DESC>
 * simple HTTP POST using the easy interface
 * </DESC>
 */ *
#*include* *<stdio.h>*
#*include* *<curl/curl.h>*
 *int* *main*(*void*)
{
  CURL *curl;
  CURLcode res;

  */* In windows, this will init the winsock stuff */ *
  curl_global_init
<https://curl.haxx.se/libcurl/c/curl_global_init.html>(CURL_GLOBAL_ALL);

  */* get a curl handle */ *
  curl = curl_easy_init <https://curl.haxx.se/libcurl/c/curl_easy_init.html>();
  *if*(curl) {
    */* First set the URL that is about to receive our POST. This URL can
       just as well be a https:// URL if that is what should receive the
       data. */ *
    curl_easy_setopt
<https://curl.haxx.se/libcurl/c/curl_easy_setopt.html>(curl,
CURLOPT_URL <https://curl.haxx.se/libcurl/c/CURLOPT_URL.html>,
*"http://postit.example.com/moo.cgi
<http://postit.example.com/moo.cgi>"*);
    */* Now specify the POST data */ *
    curl_easy_setopt
<https://curl.haxx.se/libcurl/c/curl_easy_setopt.html>(curl,
CURLOPT_POSTFIELDS
<https://curl.haxx.se/libcurl/c/CURLOPT_POSTFIELDS.html>,
*"name=daniel&project=curl"*);

    */* Perform the request, res will get the return code */ *
    res = curl_easy_perform
<https://curl.haxx.se/libcurl/c/curl_easy_perform.html>(curl);
    */* Check for errors */ *
    *if*(res != CURLE_OK)
      fprintf(stderr, *"curl_easy_perform
<https://curl.haxx.se/libcurl/c/curl_easy_perform.html>() failed:
%s\n"*,
              curl_easy_strerror
<https://curl.haxx.se/libcurl/c/curl_easy_strerror.html>(res));

    */* always cleanup */ *
    curl_easy_cleanup
<https://curl.haxx.se/libcurl/c/curl_easy_cleanup.html>(curl);
  }
  curl_global_cleanup
<https://curl.haxx.se/libcurl/c/curl_global_cleanup.html>();
  *return* 0;
}

---------------------------------

When this is compiled and runs, it goes out to the example site and get the
data as it should but then it is printing it to the console (Ubuntu 16.04).

I'm a bit rusty on my C/C++ and am getting back into things, but what I see
that only "fprintf" function that should display something if there is an
error to the "stderr" device.

Where is the code setting that is sending the URL data to the console and
can that be turned off, or on, as needed?

Other examples seem to show how to setup a callback function that can
actually receive the data and move it to a memory pointer so that you can
work with it and I am looking into that as well.

Any help would be greatly appreciated.
Thanks
Lonnie

-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2018-04-15