• curl基础教程


    curl语法: curl [options] <url> 

    curl默认直接将http响应的body内容打印输出(不打印http响应头)

    User-Agent默认为: curl/版本号 ,如:User-Agent: curl/7.65.3

    http请求默认没有Referer

    默认使用HTTP/1.1

    使用案例

    1、发送GET请求,并打印输出http响应的body内容

    curl http://www.nyushukka.com/mysqltables.sql

    2、发送HEAD请求,只打印输出http响应头

    curl --head http://geotar.com/phpbb_db_backup_data.sql

    3、使用HTTP/1.0协议

    curl --http1.0 http://www.sogou.com/phpbb_db_backup_data.sql

    4、跟随302跳转

    curl --location http://www.sogou.com/

    5、将http响应的body内容写到文件中

    curl --output test1.txt http://www.sogou.com/

    6、设置Referer请求头

    curl --referer "http://www.so.com/" http://www.sogou.com/

    7、发送http PUT请求,上传test1.txt文件

    curl --upload-file test1.txt http://www.sogou.com/

    8、发送POST请求,不进行URL编码,默认使用Content-Type: application/x-www-form-urlencoded

    curl --data "username=admin&passwd=123456" http://www.sogou.com/

    9、对post请求的数据进行URL编码,"&"符号也会被编码

    curl --data-urlencode "username=admin&passwd=123456" http://www.sogou.com/

    10、忽略https证书错误

    curl --insecure https://frostyfactory.club/strandz.png

    11、添加http请求头

    curl --header "Cookies: user=admin" http://www.baidu.com/strandz.png

    12、请求ipv6地址

    curl --ipv6 http://www.google.com/

    13、post请求上传文件,uploadFile是form表单的名字

    curl -F "uploadFile=@test1.txt" http://www.baidu.com/

    POST请求的形式像下面一样:
    /****
        POST / HTTP/1.1
        Host: www.so.com
        User-Agent: curl/7.65.3
        Accept: */*
        Content-Length: 269
        Content-Type: multipart/form-data; boundary=------------------------bf349de57ad4ce17

        --------------------------bf349de57ad4ce17
        Content-Disposition: form-data; name="uploadFile"; filename="test1.txt"
        Content-Type: text/plain

        <head><title>302 Found</ti
        <center><h1>302 Found</h1></center>
        <hr><cent
        --------------------------bf349de57ad4ce17--
    ****/



  • 相关阅读:
    Java中对话框的弹出
    数据格式化和ModelAttribute注解的介绍
    SpringMVC的环境搭建
    Js基础之数组
    Js基础之函数
    POJ-3208 Apocalypse Someday (数位DP)
    HDU-6148 Valley Number (数位DP)
    [SCOI2009] [BZOJ1026] windy数
    POJ-2411 Mondriann's Dream (状压DP)
    「SCOI2005」互不侵犯 (状压DP)
  • 原文地址:https://www.cnblogs.com/dgjnszf/p/11801972.html
Copyright © 2020-2023  润新知