Curl_easy_perform çağrıldıktan sonra HTTP durum kodunu (ör. 200 veya 500) nasıl alabilirim?Http status code libcurl ile?
76
A
cevap
113
http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html
CURLINFO_RESPONSE_CODE Pass a pointer to a long to receive the last received HTTP or FTP code. This option was known as CURLINFO_HTTP_CODE in libcurl 7.10.7 and earlier. This will be zero if no server response code has been received. Note that a proxy's CONNECT response should be read with CURLINFO_HTTP_CONNECTCODE and not this.
curl_code = curl_easy_perform (session);
long http_code = 0;
curl_easy_getinfo (session, CURLINFO_RESPONSE_CODE, &http_code);
if (http_code == 200 && curl_code != CURLE_ABORTED_BY_CALLBACK)
{
//Succeeded
}
else
{
//Failed
}
1
diğer cevabı kesinlikle doğru, ama ben de o elle hata kodunu kontrol etmek akıllıca olmayabileceğini eklemek isterim, 200
kodu yalnızca değildir başarıyı gösteren kod.
ı aktive olduğunda 400
ve 500
-Kategoriler durumları bir istek başarısızlık dikkate libcurl yapacak ve gerçekleştirmek gelen CURLE_OK
geri dönmeyecek libcurl seçeneği CURLOPT_FAILONERROR kullanarak recoment olurdu.
iyi soru. başka biri olabilir, durum mesajı nasıl alınır .. :) – mykhal