1. 程式人生 > >Linux curl命令模擬Http請求(get/post),繫結host訪問

Linux curl命令模擬Http請求(get/post),繫結host訪問

linux curl模擬http請求傳送資料:

get方式提交資料:
curl -G -d “name=value&name2=value2” http://www.baidu.com

post方式提交資料:
post資料:
curl -d “name=value&name2=value2” http://www.baidu.com

post檔案:
curl -d a=b&c=d&[email protected]/tmp/txt http://www.baidu.com

以表單的方式上傳檔案,upload_file是方法名:
curl -F “

[email protected]/root/test.txt” “http://www.baidu.com/upload_file
相當於設定form表單的method=”POST”和enctype=’multipart/form-data’兩個屬性。

繫結host訪問網頁
假設訪問頁面地址為: http://www.iamlauy.com/abc/test
www.iamlauy.com 域名解析到ip: 192.168.0.1
則curl訪問方式為如下:
curl -H “Host:www.iamlauy.com” “http://192.168.0.1/abc/test