This article will give you a detailed introduction to the test example of separating header and body information in php curl. You may not have noticed it before, but I analyzed it later and will introduce it to you below.
In PHP, curl can be used to simulate http requests, and at the same time, http response header and body can be obtained. Of course, parameters can also be set to obtain only one of them. When the setting obtains the response header and body at the same time, they will be returned together as the result. At this time we need to separate them ourselves.
The following code simulates an http GET request to Google
The code is as follows | Copy code | ||||
$url = 'http://www.google.com.hk'; $ch = curl_init();
} |
代码如下 | 复制代码 |
$response = curl_exec($ch); if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == '200') { |