BIG
http reqeust sample code
case 1.
<?php
$url = 'https://www.example.com/api/endpoint';
// Use file_get_contents to make the request
$response = file_get_contents($url);
// Check if the request was successful
if ($response === false) {
echo "Request failed.";
} else {
echo "Request succeeded: $response";
}
case 2.
<?php
$url = 'https://www.example.com/api/endpoint';
// Create a cURL handle
$ch = curl_init();
// Set the URL
curl_setopt($ch, CURLOPT_URL, $url);
// Return the response as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Make the request
$response = curl_exec($ch);
// Check if the request was successful
if (curl_errno($ch)) {
echo "Request failed: " . curl_error($ch);
} else {
echo "Request succeeded: $response";
}
// Close the cURL handle
curl_close($ch);
LIST
'!!...PHP > !!...SAMPLE' 카테고리의 다른 글
[PHP]17_MariaDB 저장 프로시져 호출 sample code (0) | 2023.02.14 |
---|---|
[PHP]16_curl 을 이용한 파일 전송 샘플코드 (0) | 2023.02.13 |
[PHP]14_openai API ( chatGPT )연동 샘플 코드 (0) | 2023.02.08 |
[PHP]13_shell_exec Sample Code (0) | 2022.12.23 |
[PHP]12_문법예제 * 를 이용하여 다이아몬드 모양 출력하기 (0) | 2022.12.22 |