<?phpnamespace servers\serveridcims\controller\client;/**
* 客戶端操作伺服器類 */
class
serveridcims
}$headers = $contenttype[$type
];
//請求頭,可以傳陣列
curl_setopt($ch, curlopt_url,$url
); curl_setopt(
$ch, curlopt_httpheader,$headers
); curl_setopt(
$ch, curlopt_header, true
); curl_setopt(
$ch, curlopt_returntransfer, true); //
執行後不直接列印出來
curl_setopt($ch, curlopt_nobody,false
); curl_setopt(
$ch, curlopt_sslversion, 3);
curl_setopt(
$ch, curlopt_ssl_cipher_list, 'sslv3');
if($method == 'post')
curl_setopt(
$ch, curlopt_customrequest,'post'); //
請求方式
curl_setopt($ch, curlopt_post, true); //
post提交
curl_setopt($ch, curlopt_postfields,$data); //
post的變數
}
if($method == 'put')
curl_setopt (
$ch, curlopt_customrequest, "put");
curl_setopt(
$ch, curlopt_postfields,$data
); }
if($method == 'delete')
curl_setopt (
$ch, curlopt_customrequest, "delete");
curl_setopt(
$ch, curlopt_postfields,$data
); }
curl_setopt(
$ch, curlopt_timeout, 120); //
最大執行時間
curl_setopt($ch, curlopt_http_version, curl_http_version_1_1); //
最大執行時間
curl_setopt($ch, curlopt_ssl_verifypeer, false); //
跳過證書檢查
curl_setopt($ch, curlopt_ssl_verifyhost, false); //
不從證書中檢查ssl加密演算法是否存在
curl_setopt($ch, curlopt_sslversion, 6);
$content = curl_exec($ch); //
執行並獲取html文件內容
$headerstr = curl_getinfo($ch,curlinfo_header_out);//
執行並獲取頭部內容
list($headerinfo,$output)=explode("\r\n\r\n",$content,2);
$err = curl_error($ch
);
if($err
) curl_close(
$ch); //
釋放curl控制代碼
$response = json_decode($output, true
);
if (json_last_error() ==json_error_none)
else
else
else}}
}catch (\exception$e)
}/**
* 返回成功
*/public
function successreturn($data = , $msg = "")
/*** 返回失敗
*/public
function failreturn($msg = '', $code = 1, $data =)
}
php curl的用法總結
1 使用curl,get獲得資料 php url 初始化一個 curl 物件 ch curl init 設定你需要抓取的url curl s...
Curl操作Elasticsearch的常用方法
elasticsearch對於文件操作,提供了以下幾種api,本文就說明如何使用curl方式來呼叫這些api。 單文件操作api 1 ind...
php中curl fsockopen的應用
最近要用到通過post上傳檔案,網上盛傳的有curl的post提交和fsockopen,其中curl最簡單,於是從最簡單的說起。 這是簡單的...