curl / Mailing Lists / curl-users / Single Mail

curl-users

Re: Exists?

From: ToddAndMargo <ToddAndMargo_at_zoho.com>
Date: Mon, 6 Aug 2018 00:50:33 -0700

On 08/05/2018 04:47 PM, ToddAndMargo wrote:
> On 08/05/2018 04:20 PM, ToddAndMargo wrote:
>> On 08/05/2018 03:44 PM, Daniel Stenberg wrote:
>>> On Sun, 5 Aug 2018, ToddAndMargo wrote:
>>>
>>>> Is there a way to ask curl to tell me is a url exists without
>>>> downloading it if it does?
>>>
>>>   curl -f http://example.com/non-exists
>>>
>>
>> $ curl -f http://example.com/non-exists
>> curl: (22) The requested URL returned error: 404 Not Found
>>
>> Perfect.  Just look for the 404
>>
>> Thank you!
>>
>>
>
> Adding --head to it keep it from downloading if
> the file exists
>
> $ curl --fail --head http://example.com/non-exists
> curl: (22) The requested URL returned error: 404 Not Found
>
>
> $ curl --fail --head http://gbis.com
> HTTP/1.1 200 OK
> Date: Sun, 05 Aug 2018 23:46:25 GMT
> Server: Apache/2.2.14 (Fedora)
> X-Powered-By: PHP/5.2.9
> Set-Cookie: PHPSESSID=k8uiqbdqk4cq299r6vscdgpr41; path=/
> Expires: Thu, 19 Nov 1981 08:52:00 GMT
> Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
> pre-check=0
> Pragma: no-cache
> Connection: close
> Content-Type: text/html; charset=ISO-8859-1

Since I am calling this from a Perl 6 module, $? is
zero for exists and not zero for fail. So,

   if $RtnCode = 0 { return 1; } else { return 0; }

0 is false and 1 is true in Perl 6

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