cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Using curl to notify get request to server

From: Ray Satiro via curl-library <curl-library_at_cool.haxx.se>
Date: Wed, 13 Apr 2016 19:02:19 -0400

On 4/13/2016 5:34 AM, Thiru balaji wrote:
> is it possible that i perform curl_easy_perform without registering
> write_callback().
> This is just because I am interested just to notify the server that I
> have tried to do a get, But i dont want to download any data.

If you want to GET without the body you may be able to use a HEAD
request, see CURLOPT_NOBODY [1].

   curl_easy_setopt(curl, CURLOPT_URL, "example.com");
   curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);

Some servers will treat HEAD and GET requests differently, and in that
case you could use CURLOPT_CUSTOMREQUEST [2] to change it to GET. It's
not very nice though because the server is still going to send the
body... and if you are reusing the handle the connection it may show up
dead, so you would make sure it closes using CURLOPT_FORBID_REUSE [3].
Again this isn't a great idea, I'd only do it if you have to.

   curl_easy_setopt(curl, CURLOPT_URL, "example.com");
   curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
   curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
   curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1L);

There's another way that may work if your server treats HEAD and GET
requests differently, and that's requesting a range of a single byte.
That way the server replies with a single byte in the body and you just
ignore it in the write callback.

   curl_easy_setopt(curl, CURLOPT_URL, "example.com");
   curl_easy_setopt(curl, CURLOPT_RANGE, "0-0");

[1]: https://curl.haxx.se/libcurl/c/CURLOPT_NOBODY.html
[2]: https://curl.haxx.se/libcurl/c/CURLOPT_CUSTOMREQUEST.html
[3]: https://curl.haxx.se/libcurl/c/CURLOPT_FORBID_REUSE.html

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-04-14