Windows使用curl發送GET、POST請求

問題描述

Windows無法直接通過curl發送GET、POST請求




安裝

  1. 下載 curl for Windows,解壓到C盤
  2. 新建環境變量,變量名CURL_HOME
    在這裏插入圖片描述
  3. Path添加:;%CURL_HOME%\I386;
    在這裏插入圖片描述
  4. 查看版本:curl --version
    在這裏插入圖片描述
  5. 測試: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後的字符串

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

-F:模擬表單

curl -F "name=Xiao ming" -F "phone=13000000000" http://localhost:5555/




擴展閱讀

  1. Postman——API開發協作平臺
    在這裏插入圖片描述
  2. 需要中文嘗試——ApiPost
    在這裏插入圖片描述




參考文獻

  1. windows環境下 curl 安裝和使用
  2. curl - Tutorial
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章