Skip to content

Instantly share code, notes, and snippets.

@belocer
Last active April 15, 2020 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save belocer/84ff270815b28ba1152a204ec717a1c5 to your computer and use it in GitHub Desktop.
Save belocer/84ff270815b28ba1152a204ec717a1c5 to your computer and use it in GitHub Desktop.
Curl запрос
<?php
/*setcookie("utm_term", "test__utm_term");
setcookie("utm_compaign", "test__utm_compaign");
setcookie("utm_content", "test__utm_content");
setcookie("id", "10");
setcookie("utm_source", "test__utm_source");
setcookie("utm_medium", "test__utm_medium");*/
/*$url = 'http://45.67.56.103:8001/api/v1/utm/';
$post_data = [
"utm_term" => "utm_term",
"utm_compaign" => "utm_compaign",
"utm_content" => "utm_content",
"id" => "10",
"utm_source" => "utm_source",
"utm_medium" => "utm_medium",
];
// создание нового ресурса cURL
$ch = curl_init();
// установка URL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
$headers =[
'Authorization: uhuxzpwY.22nlL3RbLAaQHQODM88LcXvaWrpq9YYAII',
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 4s
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Указываем, что у нас POST запрос
curl_setopt($ch, CURLOPT_POST, 1);
// Добавляем переменные
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
// Выполнить запрос
curl_exec($ch);
// Закрываю соединение
curl_close($ch);
$__info = "
curl --location --request POST 'http://45.67.56.103:8001/api/v1/utm/'
--header 'Authorization: Api-Key HrgrAuIp.22XDfhawVa3vC0W0KdDQ6MxHD7bopdzZEt'
--form 'utm_term=qwe'
--form 'utm_compaign=qwe'
--form 'utm_content=qwe'
--form 'id=10'
--form 'utm_source=qwe'
--form 'utm_medium=qwe'
";*/
$curl = curl_init();
$int = random_int(1, 999);
$post_data = [
"utm_term" => "Температура",
"utm_compaign" => "Компания",
"utm_content" => "Контент",
"id" => $int,
"utm_source" => "Ресурс",
"utm_medium" => "Медиа",
];
$post_data = http_build_query($post_data);
$head =[
'Authorization: Api-Key uhuxzpwY.22nlL3RbLAaQHQODM88LcXvaWrpq9YYAII',
];
curl_setopt_array($curl, array(
CURLOPT_URL => "http://45.67.56.103:8001/api/v1/utm/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 5,
CURLOPT_POST => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTPHEADER => $head,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $post_data,
));
$response = curl_exec($curl);
$info = curl_getinfo($curl);
curl_close($curl);
echo '<pre>';
print_r($response);
print_r('------------------<br>------------------');
print_r($info);
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment