libcurl CURLOPT_WRITEFUNCTION 回调函数多次触发导致数据错乱的问题

PinkBean 2020-08-19

记录一下自己犯的错误,回调函数本身就会提供数据大小,自己算反而出了问题。

size_t Get_Receive_Data(void* buffer, size_t size, size_t nmemb, char **stream)
{
    //int len = strlen((char*)buffer);
    int len = size * nmemb;
    if(NULL != *stream)
    {
        *stream = (char*)realloc(*stream, len + strlen(*stream));
        memcpy(*stream + strlen(*stream), (char*)buffer,len);
    }
    else
    {
        *stream = (char*)malloc(len);
        memcpy(*stream,(char*)buffer, len);
    }
    //memcpy(stream,temp,strlen(temp));
    return size * nmemb;
}

相关推荐

NewActivity / 0评论 2020-05-08