Discussion:
Exists?
(too old to reply)
ToddAndMargo
2018-08-05 20:55:11 UTC
Permalink
Hi All,

Is there a way to ask curl to tell me is a url exists without
downloading it if it does?


Many thanks,
-T

-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette
Daniel Stenberg
2018-08-05 22:44:31 UTC
Permalink
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
--
/ daniel.haxx.se
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://c
ToddAndMargo
2018-08-05 23:20:13 UTC
Permalink
Post by ToddAndMargo
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!
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https:/
ToddAndMargo
2018-08-05 23:47:51 UTC
Permalink
Post by ToddAndMargo
Post by ToddAndMargo
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



-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etique
ToddAndMargo
2018-08-06 07:50:33 UTC
Permalink
Post by ToddAndMargo
Post by ToddAndMargo
Post by ToddAndMargo
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/
Aleksandar Lazic
2018-08-06 13:37:09 UTC
Permalink
Hi.
Post by ToddAndMargo
Post by ToddAndMargo
Post by ToddAndMargo
Post by ToddAndMargo
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
I would try to add --silent

***@aleks-PC ~
$ curl --silent --fail --head -o /dev/null http://gbis.com/ll ; echo $?
22

***@aleks-PC ~
$ curl --silent --fail --head -o /dev/null http://gbis.com/ ; echo $?
0

-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
E
ToddAndMargo
2018-08-06 19:51:56 UTC
Permalink
Post by Aleksandar Lazic
Hi.
Post by ToddAndMargo
Post by ToddAndMargo
Post by ToddAndMargo
Post by ToddAndMargo
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
I would try to add --silent
$ curl --silent --fail --head -o /dev/null http://gbis.com/ll ; echo $?
22
$ curl --silent --fail --head -o /dev/null http://gbis.com/ ; echo $?
0
Thank you!



-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiqu

Loading...