curl经过post向服务器请求数据,服务器返回的数据量超过1024个字节。客户端接收不完整
curl通过post向服务器请求数据,服务器返回的数据量超过1024个字节。客户端接收不完整。
客户端通过post向服务器请求数据,服务器返回的数据达到3K, 客户端接收不完整。
请问有什么办法解决吗?
服务器返回的是一个json文件内容,不完整的话就没法解析了。
memset( curl_buffer, 0, 2048 );
curl_easy_setopt(m_curl, CURLOPT_HTTPPOST, 1);
curl_easy_setopt(m_curl, CURLOPT_URL, url);
curl_easy_setopt( m_curl, CURLOPT_POSTFIELDS, post_data );//data to server
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, write_callback);//callback func, write data
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, curl_buffer);//recv buffer
------解决方案--------------------
如果你的 curl_buffer 只是一个 char *的话,当然不行啦,你的回调函数会被多次调用的。
如果要直接保存到文件,直接用fwrite和FILE *fp设置CURLOPT_WRITEFUNCTION和CURLOPT_WRITEDATA
如果要保存到内存,请参考这段代码
http://curl.haxx.se/libcurl/c/getinmemory.html
客户端通过post向服务器请求数据,服务器返回的数据达到3K, 客户端接收不完整。
请问有什么办法解决吗?
服务器返回的是一个json文件内容,不完整的话就没法解析了。
memset( curl_buffer, 0, 2048 );
curl_easy_setopt(m_curl, CURLOPT_HTTPPOST, 1);
curl_easy_setopt(m_curl, CURLOPT_URL, url);
curl_easy_setopt( m_curl, CURLOPT_POSTFIELDS, post_data );//data to server
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, write_callback);//callback func, write data
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, curl_buffer);//recv buffer
------解决方案--------------------
如果你的 curl_buffer 只是一个 char *的话,当然不行啦,你的回调函数会被多次调用的。
如果要直接保存到文件,直接用fwrite和FILE *fp设置CURLOPT_WRITEFUNCTION和CURLOPT_WRITEDATA
如果要保存到内存,请参考这段代码
http://curl.haxx.se/libcurl/c/getinmemory.html
/***************************************************************************
* _ _ ____ _
* Project ___
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
_ \
------解决方案--------------------
------解决方案--------------------
* / __
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
_)
------解决方案--------------------
------解决方案--------------------
*
------解决方案--------------------
(__
------解决方案--------------------
------解决方案--------------------
_
------解决方案--------------------
------解决方案--------------------
_ <
------解决方案--------------------
------解决方案--------------------
___
* \___
------解决方案--------------------
\___/
------解决方案--------------------
_
------解决方案--------------------
\_\_____
------解决方案--------------------
*
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
/* Example source code to show how the callback function can be used to
* download data into a chunk of memory instead of storing it in a file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
struct MemoryStruct {
char *memory;
size_t size;
};
static size_t
WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)userp;