Làm cách nào để lấy tiêu đề từ phản hồi cURL PHP?
cURL là phần mềm mà bạn có thể sử dụng để thực hiện các yêu cầu khác nhau bằng các giao thức khác nhau. PHP có tùy chọn sử dụng cURL và trong bài viết này, chúng tôi sẽ hiển thị một số ví dụ Show Khái niệm cơ bản về cURL PHPcurl_init(); // initializes a cURL session curl_setopt(); // changes the cURL session behavior with options curl_exec(); // executes the started cURL session curl_close(); // closes the cURL session and deletes the variable made by curl_init(); PHP cURL POST Yêu cầuYêu cầu POST thường được thực hiện để gửi dữ liệu do người dùng thu thập đến máy chủ 'foo', 'secondFieldData' => 'bar' ); $cURLConnection = curl_init('http://hostname.tld/api'); curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $postRequest); curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true); $apiResponse = curl_exec($cURLConnection); curl_close($cURLConnection); // $apiResponse - available data from the API request $jsonArrayResponse - json_decode($apiResponse); PHP cURL NHẬN Yêu cầuYêu cầu GET truy xuất dữ liệu từ máy chủ. Đây có thể là HTML của trang web, phản hồi API hoặc các tài nguyên khác
|