Tags
cURL , header
Asked 3 years ago
9 Jul 2021
Views 1203
web-api

web-api posted

read header http status of CURL result

want to read header what i got from CURL


$curl = curl_init();
		
		curl_setopt( $curl, CURLOPT_URL, $url );
		
		curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
		
		curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
		
		curl_setopt( $curl, CURLOPT_VERBOSE , 1 );
		
		curl_setopt( $curl , CURLOPT_HEADER, 1 );
		
		curl_setopt( $curl , CURLOPT_HTTPGET, 1 );
		
		curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );            
		
		$response = curl_exec($curl);
		curl_close ($curl);



now i want to read header what come from response web api
above call is working fine i got response in $response . if header status is good than i want to parse the result so

so basically

if($header_status ==200){
      // header status is good parse the result
}else {
      //genereate the error .
}

for that header status checking i need to grab the header from result of CURL WEB API call

Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00


how to grab the http header status


$response = curl_exec($curl);
$http_status = curl_getinfo( $curl , CURLINFO_HTTP_CODE );
if($header_status ==200){
// header status is good parse the result
}else {
//genereate the error .
}

CURLINFO_HTTP_CODE give you Last received HTTP code , which is http status .
Post Answer