Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function prepare_curl_handle($server_url, $fields, $token){
- $field = [];
- foreach ($fields as $k => $v)
- $field = array_merge($field, array($k => $v));
- $field = array_merge($field, array("token" => $token));
- $handle = curl_init($server_url);
- $user_agent=$_SERVER['HTTP_USER_AGENT'];
- curl_setopt($handle, CURLOPT_TIMEOUT, 20);
- curl_setopt($handle, CURLOPT_URL, $server_url);
- curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($handle, CURLOPT_POST, 1);
- curl_setopt($handle, CURLOPT_FOLLOWLOCATION,true);
- curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($field));
- curl_setopt($handle, CURLOPT_BINARYTRANSFER, true);
- curl_setopt($handle, CURLOPT_ENCODING, "");
- curl_setopt($handle, CURLOPT_USERAGENT, $user_agent);
- $len = strlen(json_encode($field));
- curl_setopt($handle, CURLOPT_HTTPHEADER, array(
- 'Content-Type' => 'application/json',
- 'Content-Length' => $len
- )
- );
- $reg = curl_exec($handle);
- echo json_encode($reg);
- return $handle;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement