问题现象
服务器崩溃,但是使用libcurl的下载请求却返回成功,实际下载的内容为:
{"error":{"statusCode":500,"message":"Internal Server Error"}}
原因
直接附上官方给的说明(见参考链接1):
When doing HTTP transfers, curl will perform exactly what you’re asking it to do and if successful it will not return an error.
解决办法
添加一条设置:
curl_easy_setopt(m_curl, CURLOPT_FAILONERROR, 1);
参考链接
- https://curl.haxx.se/docs/faq.html#curl_doesn_t_return_error_for_HT
- https://curl.haxx.se/libcurl/c/CURLOPT_FAILONERROR.html
延伸
[C/C++]解决curl断开网线不会返回错误的问题:https://blog.csdn.net/H_O_W_E/article/details/90757792