The Curl command is simple to use

Source: Internet
Author: User

Curl Command

Curl is a file transfer tool that works in command-line mode based on URL syntax, which supports protocols such as FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, file, and LDAP. Curl supports HTTPS authentication, and supports HTTP post, put and other methods, FTP upload, Kerberos authentication, HTTP upload, proxy server, cookies, username/password Authentication, download file breakpoint continuation, upload file breakpoint continuation,, HTTP proxy Server pipeline (proxy tunneling), even it supports IPV6,SOCKS5 proxy server, upload files via HTTP proxy server to FTP server and so on, the function is very powerful.

curl [Options] [URL ...]

Common options for Curl:

-a/--user-agent <string> Set User user-agent send to server
-basic using HTTP Basic authentication
--tcp-nodelay using the Tcp_nodelay option
-e/--referer <URL> Source URL
--cacert <file> CA Certificate (SSL)
--compressed required to return a compressed format
-h/--header <line> Custom header information to the server
-i/--head only the response message header information is displayed
--limit-rate <rate> Set Transfer speed
-u/--user <user[:p assword]> setting up the user and password for the server
-0/--http1.0 Using HTTP 1.0

Usage: curl [options] [URL ...]

Cases

[[email protected] ~]# curl  http:// 192.168.65.80[[email protected] ~]# curl -a  "I love china"   http ://192.168.65.80log:[[email protected] ~]# tail -2 /var/log/httpd/access_ log192.168.65.80 - - [29/mar/2015:10:46:26 +0800]  "GET / HTTP/1.1"  200  915  "-"   "curl/7.19.7  (X86_64-REDHAT-LINUX-GNU)  libcurl/7.19.7 NSS/3.15.3  zlib/1.2.3 libidn/1.18 libssh2/1.4.2 "192.168.65.80 - - [29/mar/2015:10:46:29 + 0800]  "get / http/1.1"  200 915  "-"   "I love china" 
[[email protected] ~]# Curl Http://192.168.65.80[[email protected] ~]# curl-e "www.gov.cn" http://192.168.65.80log:[[e Mail protected] ~]# tail-2/var/log/httpd/access_log192.168.65.80--[29/mar/2015:10:58:40 +0800] "get/http/1.1" 200 9 "-" "curl/7.19.7 (X86_64-REDHAT-LINUX-GNU) libcurl/7.19.7 nss/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2" 192.168.65.80--[29/mar/2015:10:58:43 +0800] "get/http/1.1" 915 "www.gov.cn" curl/7.19.7 (X86_64-redhat-linux-gnu ) libcurl/7.19.7 nss/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 "

Get Response message header information

[Email protected] ~]# curl-i http://192.168.65.80HTTP/1.1 okdate:sun, Mar 02:45:06 gmtserver:apache/2.2.15 (CentOS) Dav/2connection:closecontent-type:text/html;charset=utf-8



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

The following source: http://lijunjie.iteye.com/blog/395270

It says something important is missing out! -----Use Curl to download files

Just now, download the page to a file, you can use-o, download the same file.
For example, Curl-o 1.jpg Http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
Here we teach you a new option:-O
Uppercase O, so used: Curl-o Http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
In this way, you can follow the file name on the server, automatically exist locally!

Another better use.
If Screen1. There are also screen2.jpg and screen3 outside of JPG. JPG 、....、 Screen10. JPG needs to be downloaded, is it difficult for us to write a script to complete these operations?
Don't do it!
In curl, this is the way to write:
Curl-o http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10]. Jpg

Oh, what a bad, huh?! ~~~

9)
Come again, we continue to explain the download!
Curl-o http://cgi2.tky.3web.ne.jp/~/[001-201]. Jpg

The resulting download is
~zzh/001.jpg
~zzh/002.jpg
...
~zzh/201.jpg
~nick/001.jpg
~nick/002.jpg
...
~nick/201.jpg

Is it convenient enough? Ha ha haha

Hey? It's too early to be happy.
Because the Zzh/nick under the file name are 001,002...,201, downloaded files with the same names, the back of the previous files are covered out ~ ~ ~

It's OK, we have more ruthless!
Curl-o #2_ #1.jpg http://cgi2.tky.3web.ne.jp/~/[001-201]. Jpg

-This is ..... Custom file name download?
--to the enemy, hehe!

#1是变量, refers to this part, the first time value Zzh, the second time to take the value of Nick
#2代表的变量, it is the second variable part---[001-201], the value is added from 001 to 201
In this way, the name of the downloaded file is customized, and it becomes this:
Original: ~zzh/001.jpg---> After download: 001-zzh. Jpg
Original: ~nick/001.jpg---> After download: 001-nick. Jpg

In this way, not afraid of the file name, hehe


9)
Continue to download
We usually on the Windows platform, flashget such a tool can help us to block parallel download, but also can be disconnected to continue transmission.
Curl in these areas also do not lose to who, hehe

For example, we download screen1. JPG, and suddenly dropped, so we can start the continuation.
Curl-c-O Http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG

Of course, you don't have to take a flashget download half of the files to fool me ~ ~ ~ ~ half of the other download software files may not be able to use OH ~ ~ ~

Block download, we can use this option:-R
Examples Show
For example we have a Http://cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 to download (Zhao Teacher's telephone recitation 650) this.width=650; "Src=" http://lijunjie.iteye.com /images/smiles/icon_biggrin.gif "alt=" Icon_biggrin.gif "/>)
We can use this command:
Curl-r 0-10240-o "Zhao.part1" Http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
Curl-r 10241-20480-o "Zhao.part1" Http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
Curl-r 20481-40960-o "Zhao.part1" Http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
Curl-r 40961--O "Zhao.part1" Http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3

This will allow you to download the tiles.
But you need to merge the broken files yourself.
If you use UNIX or apples, use cat zhao.part* > Zhao.mp3 to
If the use of Windows, with copy/b to solve it, hehe

The above is the HTTP protocol download, in fact, FTP can also be used.
Usage,
Curl-u name:passwd Ftp://ip:port/path/file
or familiar to everyone.
Curl Ftp://name:[email protected]:p ort/path/file



10)
After the download, it is natural to upload the next.
The option to upload is-t

For example, we send a file to ftp: curl-t localfile-u name:passwd ftp://upload_site:port/path/

Of course, uploading files to an HTTP server can also
Like Curl-t LocalFile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi.
Note that at this time, the protocol used is the put method of HTTP

Just said put, hey, naturally let the old service think up the other several methos have not said it!
Neither get nor post can be forgotten.

HTTP submits a form, more commonly used is the post mode and get mode

Get mode what option is not needed, just write the variable in the URL.
Like what:
Curl http://www.yahoo.com/login.cgi?user=nickwolfe&password=12345

The option for Post mode is-D

For example, curl-d "user=nickwolfe&password=12345" http://www.yahoo.com/login.cgi
is equivalent to issuing a login request to this site ~~~~~

In the end to use the Get mode or post mode, the opposite server to see the program settings.

It is important to note that file uploads on files in post mode, such as
<form method= "POST" enctype= "Multipar/form-data" action= "http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi" >
<input Type=file name=upload>
<input type=submit name=nick value= "Go" >
</form>
Such an HTTP form, which we want to emulate with curl, is the syntax:
curl-f [email protected]-F Nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi

Ro-Ro said so much, actually curl has a lot of tricks and usage
For example, when you use local certificates for HTTPS, you can
CURL-E Localcert.pem Https://remote_server

For example, you can also use curl to check the dictionary through the Dict protocol ~~~~~
Curl Dict://dict.org/d:computer


Reference: http://lijunjie.iteye.com/blog/395270



This article is from the "impermanence" blog, please be sure to keep this source http://1inux.blog.51cto.com/10037358/1641271

The Curl command is simple to use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.