现在的位置: 首页 > 综合 > 正文

Linux CURL的安装和使用

2013年10月08日 ⁄ 综合 ⁄ 共 1543字 ⁄ 字号 评论关闭

http://blog.csdn.net/lifan5/article/details/7350154

--获得安装包,从网上直接下载或者其他途径,这里直接wget
# wget http://curl.haxx.se/download/curl-7.17.1.tar.gz
--解压到当前目录
# tar -zxf curl-7.17.1.tar.gz
--进入解压后的目录内
# cd curl-7.17.1
--配置,指定安装的目录,这里是“/usr/local/curl”
# ./configure --prefix=/usr/local/curl
--
# make
--安装
# make install
--安装完毕

使用:
将curl命令加入环境变量,
命令行里执行(仅对本会话起作用,或者在.bash_profile、.bashrc文件里配置环境变量):
# export PATH=$PATH:/usr/local/curl/bin

然后就可以使用了
# curl http://www.baidu.com
出来好多html代码,是百度首页的代码
入门的使用说明:
http://www.javaeye.com/topic/648143

详细命令讲解和实例  http://linux.chinaitlab.com/command/830656.html
-------------------------------------------------------------------------------------------

请求实例 (运用curl):
curl --request POST --data-binary @datafile.txt --header "U-ApiKey: YOUR_API_KEY_HERE" http://api.yeelink.net/v1.0/device/12/sensor/3/datapoints
需要在HTTP Header中增加API Key来授权写入操作, 具体请参照API
Key
. 支持一次传送一个数据或者批量上传.


请求实例 (运用curl):
curl --request GET --header "U-ApiKey: YOUR_API_KEY_HERE" http://api.yeelink.net/v1.0/device/12/sensor/3/datapoint/2012-03-15T16:13:14




使用实例(发送POST请求):
# curl -d @json http://www.google.com/loc/json

-d —— 是以POST形式发送请求
@json —— @是从文件中读取数据,json文件中的内容为{"address_language":"zh_CN","cell_towers":[{"cell_id":"36526","location_area_code":"14556","mobile_contry_code":"460","mobile_network_code":"02"}],"host":"maps.google.com","location":null,"request_address":true,"version":"1.1.0","wifi_towers":[]}

返回:
{"location":{"latitude":32.117302,"longitude":114.116598,"address":{"country":"中国","country_code":"CN","region":"河南省","city":"信阳市"},"accuracy":1625.0},"access_token":"2:FaXK0Xl_DHRbcQiK:5tGTJsZx1scpjUfJ"}

抱歉!评论已关闭.