隨筆-314  評(píng)論-209  文章-0  trackbacks-0

          可參照:http://www.voidcn.com/blog/Vindra/article/p-4917667.html

          一、get請(qǐng)求 

          curl "http://www.baidu.com"  如果這里的URL指向的是一個(gè)文件或者一幅圖都可以直接下載到本地

          curl -i "http://www.baidu.com"  顯示全部信息

          curl -l "http://www.baidu.com" 只顯示頭部信息

          curl -v "http://www.baidu.com" 顯示get請(qǐng)求全過程解析

           

          wget "http://www.baidu.com"也可以

           

          二、post請(qǐng)求

          curl -d "param1=value1&param2=value2" "http://www.baidu.com"

           

          三、json格式的post請(qǐng)求

          curl -l -H "Content-type: application/json" -X POST -d '{"phone":"13521389587","password":"test"}' http://domain/apis/users.json

          例如:

          curl -l -H "Content-type: application/json" -X POST -d '{"ver": "1.0","soa":{"req":"123"},"iface":"me.ele.lpdinfra.prediction.service.PredictionService","method":"restaurant_make_order_time","args":{"arg2":"\"stable\"","arg1":"{\"code\":[\"WIND\"],\"temperature\":11.11}","arg0":"{\"tracking_id\":\"100000000331770936\",\"eleme_order_id\":\"100000000331770936\",\"platform_id\":\"4\",\"restaurant_id\":\"482571\",\"dish_num\":1,\"dish_info\":[{\"entity_id\":142547763,\"quantity\":1,\"category_id\":1,\"dish_name\":\"[0xe7][0x89][0xb9][0xe4][0xbb][0xb7][0xe8][0x85][0x8a][0xe5][0x91][0xb3][0xe5][0x8f][0x89][0xe7][0x83][0xa7][0xe5][0x8f][0x8c][0xe6][0x8b][0xbc][0xe7][0x85][0xb2][0xe4][0xbb][0x94][0xe9][0xa5][0xad]\",\"price\":31.0}],\"merchant_location\":{\"longitude\":\"121.47831425\",\"latitude\":\"31.27576153\"},\"customer_location\":{\"longitude\":\"121.47831425\",\"latitude\":\"31.27576153\"},\"created_at\":1477896550,\"confirmed_at\":1477896550,\"dishes_total_price\":0.0,\"food_boxes_total_price\":2.0,\"delivery_total_price\":2.0,\"pay_amount\":35.0,\"city_id\":\"1\"}"}}' http://vpcb-lpdinfra-stream-1.vm.elenet.me:8989/rpc

          ps:json串內(nèi)層參數(shù)需要格式化

          posted on 2017-05-18 11:28 xzc 閱讀(1655) 評(píng)論(1)  編輯  收藏 所屬分類: linux/unix

          評(píng)論:
          # re: curl模擬http發(fā)送get或post接口測(cè)試 2017-05-18 11:28 | xzc

          Curl是Linux下一個(gè)很強(qiáng)大的http命令行工具,其功能十分強(qiáng)大。

          一、CURL對(duì)HTTP的常規(guī)訪問

          1. 訪問網(wǎng)站

          $ curl http://www.linuxidc.com

          回車之后,www.linuxidc.com 的html 顯示在屏幕上了

          2. 保存頁面

          用curl option: -o

          $ curl -o page.html http://www.linuxidc.com

          可以看到屏幕上出現(xiàn)一個(gè)下載頁面進(jìn)度指示,等到100%,就保存完成了.

          二、GET模式

          GET模式什么option都不用,只需要把變量寫在url里面就可以了,

          例如:

          $ curl http://www.linuxidc.com/test.cgi?param1=nickwolfe&param2=12345

          三、POST模式

          使用 option -d,

          例如:

          $ curl -d "param2=nickwolfe&param2=12345" http://www.linuxidc.com/login.cgi

          更多   回復(fù)  更多評(píng)論
            
          主站蜘蛛池模板: 太谷县| 澄迈县| 泊头市| 白玉县| 蕲春县| 永泰县| 鹿泉市| 德保县| 安新县| 河源市| 贡嘎县| 滁州市| 玉林市| 海淀区| 海城市| 宜城市| 新乡县| 栾川县| 孟州市| 彭山县| 云阳县| 平舆县| 德兴市| 沂水县| 逊克县| 扎鲁特旗| 安国市| 和硕县| 兴业县| 白沙| 佛山市| 土默特左旗| 阳泉市| 永登县| 青浦区| 营山县| 司法| 汾西县| 连平县| 西林县| 巧家县|