jojo's blog--快乐忧伤都与你同在
为梦想而来,为自由而生。 性情若水,风起水兴,风息水止,故时而激荡,时又清平……
posts - 11,  comments - 30,  trackbacks - 0
<?php
/*
* Created on Feb 12, 2008
*
* Donald J. Ankney
* Academic Personnel Information Services
* ankneyd@u.washington.edu
*
* Class is a REST webservice client
* can use SSL
*
*/


class RestClient {
public $certPath;
public $keyPath;
public $uriBase;

// Method pulls the resource via curl and returns a string of the resource
function getResource ($uri) {
$ch = curl_init($this->uriBase.$uri);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//TODO: VERIFYPEER is necessary for enterprise use, implement some rules around it
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
if ($this->keyPath AND $this->certPath) { // if cert/key attributes are set, use them
curl_setopt($ch, CURLOPT_SSLCERT, $this->certPath);
curl_setopt($ch, CURLOPT_SSLKEY, $this->keyPath);
}

$resource=curl_exec($ch);
$info = curl_getinfo($ch);
if ($info1 != '200') {
//TODO: Better error handling
return FALSE;
};
curl_close($ch);
return $resource;
}
}

$webQ = new RestClient;
$webQ->uriBase = 'https://catalysttools.washington.edu/rest/webq/v1';
$webQ->certPath = '/Path/to/cert.pem';
$webQ->keyPath = '/Path/to/key.pem';

$result = $webQ->getResource("/survey/number");//Or whatever you need do construct to pull the data
if ($result) {
//Do something with the resource
} else {
//TODO: Better error handling
echo "ERROR: http transfer problem";
}

?>
posted on 2008-10-07 18:19 Blog of JoJo 阅读(204) 评论(0)  编辑  收藏 所属分类: Linux 技术相关

只有注册用户登录后才能发表评论。


网站导航:
 

<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(6)

随笔档案

文章分类

文章档案

新闻分类

新闻档案

相册

收藏夹

搜索

  •  

最新评论

阅读排行榜

评论排行榜