Skip to content

Instantly share code, notes, and snippets.

@Ginnw2
Created April 6, 2022 06:03
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 Ginnw2/685a3172adc1427e307cdcc5d8fcda04 to your computer and use it in GitHub Desktop.
Save Ginnw2/685a3172adc1427e307cdcc5d8fcda04 to your computer and use it in GitHub Desktop.
$url = 'https://domain.pr/anything';
$headers = ['Content-Type: application/json']; // заголовки нашего запроса
$post_data = [ // поля нашего запроса
'field1' => 'val_1',
'field2' => 'val_2',
];
$data_json = json_encode($post_data); // переводим поля в формат JSON
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
$result = curl_exec($curl); // результат POST запроса
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment