ecshop请求restful的api
2015-03-24 10:27 来源:www.chinab4c.com 作者:ecshop专家
最近需要使用ecshop请求外界的restful接口,我们知道ecshop程序是php的,所以这个时候我们只要使用ecshop调用php curl来完成ecshop对restful接口的请求。下面我们看以下代码。
if ($_GET['act'] == 'delete') {
$curl_handle = curl_init ();
curl_setopt ( $curl_handle, CURLOPT_URL, 'http://localhost:8080/v1/user/222');
curl_setopt ( $curl_handle, CURLOPT_FILETIME, true );
curl_setopt ( $curl_handle, CURLOPT_FRESH_CONNECT, false );
curl_setopt ( $curl_handle, CURLOPT_HEADER, true );
curl_setopt ( $curl_handle, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $curl_handle, CURLOPT_TIMEOUT, 5184000 );
curl_setopt ( $curl_handle, CURLOPT_CONNECTTIMEOUT, 120 );
curl_setopt ( $curl_handle, CURLOPT_NOSIGNAL, true );
curl_setopt ( $curl_handle, CURLOPT_CUSTOMREQUEST, 'DELETE' );
$ret = curl_exec ( $curl_handle );
print_r($ret);
}
if ($_GET['act'] == 'put') {
//PUT
$curl_handle = curl_init ();
// Set default options.
curl_setopt ( $curl_handle, CURLOPT_URL, 'http://localhost:8080/v1/user/user_11111');
curl_setopt ( $curl_handle, CURLOPT_FILETIME, true );
curl_setopt ( $curl_handle, CURLOPT_FRESH_CONNECT, false );
curl_setopt ( $curl_handle, CURLOPT_HEADER, true );
curl_setopt ( $curl_handle, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $curl_handle, CURLOPT_TIMEOUT, 5184000 );
curl_setopt ( $curl_handle, CURLOPT_CONNECTTIMEOUT, 120 );
curl_setopt ( $curl_handle, CURLOPT_NOSIGNAL, true );
curl_setopt ( $curl_handle, CURLOPT_HEADER, true );
curl_setopt ( $curl_handle, CURLOPT_CUSTOMREQUEST, 'PUT' );
$aHeader[] = "Content-Type:text/xml;charset=UTF-8";
$aHeader[] = "x-bs-ad:private";
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $aHeader);
$file = 'client.php';
$file_size = filesize($file);
$h = fopen($file,'r');
curl_setopt ( $curl_handle, CURLOPT_INFILESIZE, $file_size);
curl_setopt ( $curl_handle, CURLOPT_INFILE, $h);
curl_setopt ( $curl_handle, CURLOPT_UPLOAD, true );
$ret = curl_exec ( $curl_handle );
print_r($ret);
}
来源:http://www.chinab4c.com
最近更新
常用插件
- ecshop通用红包编码
很多时候,为了结合促销,必须扩展一下ecshop的红包功能。ecshop的红包...
- ecshop降价通知登记插件
ecshop降价通知登记插件,主要是为了方便某些客户,对商品价格要求比...
- ecshop分类树中统计商品数
最近忙于开发其他项目,在不少朋友不断要求和催促的情况下,做出了该小...
- ecshop购物车功能改进[插件
ecshop购物车功能改进[插件套餐]主要是我们最近开发工作和开发项目中。...
- ecshop红包修改成满多少减
我们在长期使用ecshop的时候,我们可以发现。ecshop的红包是一个非常强...