使用curl_exec()函数执行cURL会话。这个函数会返回请求的结果,如果设置了CURLOPT_RETURNTRANSFER为true,则返回结果字符串,否则直接输出结果。 获取HTTP响应的状态码: 使用curl_getinfo()函数并传入CURLINFO_HTTP_CODE作为第二个参数,可以获取HTTP响应的状态码。 关闭cURL会话: 使用curl_close()函数关闭cURL会话并释放相...
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); // 获取状态码 curl_close($curl); if ($status_code == ‘200’) { echo “页面正常访问”; } else { echo “页面访问异常,状态码为:”.$status_code; } “` 3. 使用`file_get_contents()`函数:这是一个简单的获取URL内容的方法,...
curl_setopt($ch, CURLOPT_HEADER, 1); $response = curl_exec($ch); $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); “` 2. 使用file_get_contents函数获取状态码:`file_get_contents()`函数可以读取文件内容,也可以通过指定URL来获取网页内容。可以通过`$http_response_h...
其中 CURLOPT_VERBOSE, CURLOPT_STDERR 是 curl dubug 的关键项。安装
NOBODY选项设置为不接收正文。然后,您可以使用curl_getinfo获取状态代码。
$result = curl_exec($http); $http_status = curl_getinfo($http, CURLINFO_HTTP_CODE); echo $http_status; curl_getinfo()returns data for the last curl request, so you must execute the cURL call first, then callcurl_getinfo(). The key is the second argument; the predefined constantCUR...
$response=curl_exec($ch); 复制代码 处理响应:对于HTTP请求的响应,可以使用curl_getinfo()函数获取响应的相关信息,例如状态码、响应头等。 $status_code=curl_getinfo($ch, CURLINFO_HTTP_CODE);$header_size=curl_getinfo($ch, CURLINFO_HEADER_SIZE);$headers=substr($response,0,$header_size);$body=...
}echoget_http_status_code($url); 另一种获取http状态码的办法 使用curl需要在php.ini中设置启用才行 >< Windows的服务器中,打开php.ini,找到: extension=php_curl.dll 去掉前面的注释既可 。 $curl=curl_init();$url=’http://www.111cn.net’;curl_setopt($curl, CURLOPT_URL,$url);//设置URLcur...
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization:'.$token)); $response = curl_exec($request); $errors = curl_error($request); $httpcode = curl_getinfo($request, CURLINFO_HTTP...
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($http_status == 200) { echo “请求成功”; } else { echo “请求失败”; } “` 在上面的代码中,使用curl_getinfo函数获取CURL的一些信息,其中包括HTTP状态码。通过判断$http_status的值,可以得知CURL执行的状态。