Curl command, curl
Curl is a command line tool that supports multiple protocols. It sends network requests, obtains and extracts data, and displays the data on stdout.
On the server side, using curl to check whether the request address returns data to determine whether the problem is nginx configuration or program service configuration (curl-I "...")!
1. view the webpage source code and add the URL directly after the curl command to view the webpage source code:
curl www.sina.com
If you want to save the webpage, you can use the-o parameter, which is equivalent to using the wget command.
Curl-o [file name] www.sina.com
2. Some websites are automatically redirected. With the-L parameter, curl will jump to the new URL.
curl -L www.sina.com
Enter the preceding command, and the result is automatically redirected to www.sina.com.cn and the source code is displayed.
3. Show header information-the I parameter only displays http response header information.
-The I parameter can display the http response header information, along with the webpage code.
curl -I www.sina.comcurl -i www.sina.com
HTTP/1.1 301 Moved PermanentlyServer: nginxDate: Wed, 17 Jun 2015 13:54:42 GMTContent-Type: text/htmlLocation: http://www.sina.com.cn/Expires: Wed, 17 Jun 2015 13:56:42 GMTCache-Control: max-age=120Age: 102Content-Length: 178X-Cache: HIT from xd33-96.sina.com.cn4. display the communication process-the v parameter can display the entire http Communication Process, including the port connection and http request header information.
curl -v www.sina.com
View More detailed communication process:
curl --trace output.txt www.sina.com
Or
curl --trace-ascii output.txt www.sina.com
After running, open the output.txt file.
5. Send form information send form information (GET ):
curl example.com/form.cgi?data=xxx
Send form information (POST ):
curl --data "data=xxx" example.com/form.cgi
Send form information, data encoding (POST ):
curl --data-urlencode "date=April 1" example.com/form.cgi
6. HTTP verb curl the default HTTP verb is GET. Other verbs can be supported using the-X parameter.
curl -X POST www.example.comcurl -X DELETE www.example.com
VII. The Referer field sometimes needs to provide a referer field in the http request header to indicate where to jump.
curl --referer http://www.example.com http://www.example.com
8. The User Agent field indicates the device information of the client. The server sometimes returns webpages in different formats for different devices based on this field.
curl --user-agent "[User Agent]" [URL]
9. cookiecurl:
curl --cookie "name=xxx" www.example.com
10. Add a header in the http request. -- The header parameter can play this role.
curl --header "Content-Type:application/json" http://example.com
11. HTTP authentication for some domains requires HTTP authentication. In this case, the -- user parameter is required for curl.
curl --user name:password example.com
Reference: http://www.ruanyifeng.com/blog/2011/09/curl.html