Curl Error Handling Command Line
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about curl error handling bash hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask php curl error handling Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join
Curl Command Line Examples
them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How to check whether a command such as curl
Curl Command Line Windows
completed without error? up vote 7 down vote favorite 1 I am using curl to upload a file to a server via an HTTP post. curl -X POST -d@myfile.txt server-URL When I manually execute this command on the command line, I get a response from the server like "Upload successful". However, how if I want to execute this curl command via a script, how can I find out if my POST request was successful? curl http error-handling share|improve this question curl command line post edited Apr 16 '14 at 2:51 user61786 asked Apr 15 '14 at 15:44 Wes 1792215 add a comment| 2 Answers 2 active oldest votes up vote 10 down vote accepted The simplest way is to store the response and compare it: $ response=$(curl -X POST -d@myfile.txt server-URL); $ if [ "Upload successful" == "${response}" ]; then … fi; I haven't tested that. The syntax might be off, but that's the idea. I'm sure there are more sophisticated ways of doing it such as checking curl's exit code or something. update curl returns quite a few exit codes. I'm guessing a failed post might result in 55 Failed sending network data. So you could probably just make sure the exit code was zero by comparing to $? (Expands to the exit status of the most recently executed foreground pipeline.): $ curl -X POST -d@myfile.txt server-URL; $ if [ 0 -eq $? ]; then … fi; Or if your command is relatively short and you want to do something when it fails, you could rely on the exit code as the condition in a conditional statement: $ if curl --fail -X POST -d@myfile.txt server-URL; then # …(success) else # …(failure) fi; I think this format is often preferred, but personally I find it less readable. share|improve this answer edited Nov 5 '14 at 5:07 Jorge Bucaran 237111 answered Apr 15 '14 at 15:52 user61786 add a comment| up vote 3 down
[options] [URL...] DESCRIPTION curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP,
Curl Command Line Header
SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction. curl command line examples https curl offers a busload of useful tricks like proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer resume, Metalink, curl command line download and more. As you will see below, the number of features will make your head spin! curl is powered by libcurl for all transfer-related features. See libcurl(3) for details. URL The URL syntax is protocol-dependent. You'll find a detailed http://unix.stackexchange.com/questions/124918/how-to-check-whether-a-command-such-as-curl-completed-without-error description in RFC 3986. You can specify multiple URLs or parts of URLs by writing part sets within braces as in: http://site.{one,two,three}.com or you can get sequences of alphanumeric series by using [] as in: ftp://ftp.example.com/file[1-100].txt ftp://ftp.example.com/file[001-100].txt (with leading zeros) ftp://ftp.example.com/file[a-z].txt Nested sequences are not supported, but you can use several ones next to each other: http://example.com/archive[1996-1999]/vol[1-4]/part{a,b,c}.html You can specify any amount of URLs on the command line. They will be fetched https://curl.haxx.se/docs/manpage.html in a sequential manner in the specified order. You can specify a step counter for the ranges to get every Nth number or letter: http://example.com/file[1-100:10].txt http://example.com/file[a-z:2].txt When using [] or {} sequences when invoked from a command line prompt, you probably have to put the full URL within double quotes to avoid the shell from interfering with it. This also goes for other characters treated special, like for example '&', '?' and '*'. Provide the IPv6 zone index in the URL with an escaped percentage sign and the interface name. Like in http://[fe80::3%25eth0]/ If you specify URL without protocol:// prefix, curl will attempt to guess what protocol you might want. It will then default to HTTP but try other protocols based on often-used host name prefixes. For example, for host names starting with "ftp." curl will assume you want to speak FTP. curl will do its best to use what you pass to it as a URL. It is not trying to validate it as a syntactically correct URL by any means but is instead very liberal with what it accepts. curl will attempt to re-use connections for multiple file transfers, so that getting many files from the same server will not do multiple connects / handshakes. This improves speed. Of course this is only done on files specified on a single command line and cannot be used
[ More options ] Related messages: [ Next message ] [ Previous message ] [ Next in thread ] [ Replies ] From: TP The op eration succeeded with success code 100
<< 2nd response >>HTTP/1.1 403 FORBIDDEN Connection: close Server: RTS-HTTPD $Revision: 1.5 $ Content-Type: text/html I will get a returncode not equal to zero if the webserver threw only one response with the error. How can I detect this error from the commandline? Please help Kind regards thomas Received on 2006-10-25 This message: [ Message body ] Next message: Daniel Stenberg: "Re: No Errorcode in commandline will be returned even http errors occ ured" Previous message: Daniel Stenberg: "Re: Re SSL Upload" Next in thread: Daniel Stenberg: "Re: No Errorcode in commandline will be returned even http errors occ ured" Reply: Daniel Stenberg: "Re: No Errorcode in commandline will be returned even http errors occ ured" Maybe reply: TP: "Re: No Errorcode in commandline will be returned even http errors occ ured" Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]