1. CURLOPT_FAILONERROR
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FAILONERROR, long fail);
当http code >= 400时,默认是返回页面。通过这个把fail设置为1,perform执行的请求会是失败。
https://curl.se/libcurl/c/CURLOPT_FAILONERROR.html
代码语言:javascript复制CURL *curl = curl_easy_init();
if(curl) {
CURLcode ret;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
ret = curl_easy_perform(curl);
if(ret == CURLE_HTTP_RETURNED_ERROR) {
/* an HTTP response error problem */
}
}
2. 速度限制