欢迎各位兄弟 发布技术文章
这里的技术是共享的
function _my_get_base64_encode()
{
$name = 'xxxx';
$pwd = 'yyyyy';
return base64_encode("$name:$pwd");
}
function _my_curl_endpoint($filter = '', $method = 'GET', $data_arr = array())
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://xxx.yyyy.2.43:9060/ers/config/endpoint" . $filter);
$headers = array('Authorization:Basic ' . _my_get_base64_encode(), 'Accept: application/json', 'ERS-Media-Type: identity.endpoint.1.2', 'Content-Type: application/json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // to resolve your current error
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
if (!empty($data_arr)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, drupal_json_encode($data_arr));
}
$response = curl_exec($ch);
if (curl_error($ch)) {
$response = curl_error($ch);
}
curl_close($ch);
return $response;
}