- c++
C++,post请求响应为空,怎么重复请求,直到请求成功返回正确的响应!代码怎么实现
比如
token=gettoken();
response_data =curl_post(“www.test.com” ,token,request_data);
返回2种情况:
1、空,请求时间过长导致请求响应为空
2、{“data”:“value”},正确返回响应数据.
std::string Post_Response()
{
std::string request_data;
std::string response_data;
int count = 0;
while ((count == 0 && response_data.empty()) || count == 1)
{
response_data =curl_post(“www.test.com” ,token,request_data);
if (count == 0)
count++;
if (response_data.empty()) //为空则循环请求
{
printf("post error!n");
}
else break; //不为空,获取到了正确的响应,跳出循环
}
return response_data;
}



