您当前的位置: 首页 >  windows

顺其自然~

暂无认证

  • 2浏览

    0关注

    1317博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Windows使用curl发送GET、POST请求

顺其自然~ 发布时间:2022-06-15 09:25:07 ,浏览量:2

问题描述

Windows无法直接通过curl发送GET、POST请求

安装

下载 curl for Windows

将 bin 目录添加到环境变量 Path

查看版本:curl --version

测试:curl www.baidu.com

基本使用

获取百度首页

curl http://www.baidu.com/

获取funet ftp服务器上的README

curl ftp://ftp.funet.fi/README

更多用法查看curl - Tutorial

GET请求

用Tornado构建API用于GET、POST请求测试

import tornado.web
import tornado.ioloop


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        name = self.get_argument('name', default='')
        phone = self.get_argument('phone', default='')
        self.write('GET {} {}'.format(name, phone))

    def post(self):
        name = self.get_argument('name', default='')
        phone = self.get_argument('phone', default='')
        self.write('POST {} {}'.format(name, phone))


if __name__ == '__main__':
    print('curl "http://localhost:5555/?name=Xiao%20ming&phone=13000000000"')  # GET
    print('curl -d "name=Xiao%20ming&phone=13000000000" http://localhost:5555/')  # POST
    print('curl -F "name=Xiao ming" -F "phone=13000000000" http://localhost:5555/')  # POST
    app = tornado.web.Application([
        (r'/', MainHandler),
    ])
    app.listen(5555)
    tornado.ioloop.IOLoop.current().start()

GET请求

curl "http://localhost:5555/?name=Xiao%20ming&phone=13000000000"
POST请求

-d:接受urlencode后的字符串(data)

curl -d "name=Xiao%20ming&phone=13000000000" http://localhost:5555/

-F:模拟表单(form)

curl -F "name=Xiao ming" -F "phone=13000000000" http://localhost:5555/
POST发文件
curl -X POST "http://xxx" --form "file=@a.png"
美化输出

下载 jq

重命名为 jq.exe

放在 C:\Windows\System32 中

调用命令 echo {"a": 1} | jq

计时
curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" "http://www.kklinux.com"
下载文件
wget -O result.pdf http://127.0.0.1:5000/download/
扩展阅读

Postman——API开发协作平台在这里插入图片描述

需要中文尝试——ApiPost在这里插入图片描述

参考文献
  1. windows环境下 curl 安装和使用
  2. curl - Tutorial
  3. Formatting cURL Output in the Windows Terminal

转自:Windows使用curl发送GET、POST请求_XerCis的博客-CSDN博客_curl windows 

关注
打赏
1662339380
查看更多评论
立即登录/注册

微信扫码登录

0.0398s