I am using libcurl for performing HTTP request and response to my webpage. But when getting the response, I am not getting the complete server response. the response lines get truncated at one point. e.g
10-25 15:53:22.264: XXX(14847): Security.8021x:true
10-25 15:53:22.264: XXX(14847): Event.AlarmInput:true
10-25 15:53:22.264: XXX(14847): Event.AlarmInput.Notification.HTTP.CGI:true
10-25 15:53:22.264: XXX(14847): Event.AlarmInput.Notification.HTTP.CGI.SingleSession:true
10-25 15:53:22.264: XXX(14847): Event.AlarmInpu .............
Note: this is a custom android log. please don't confuse with the output lines
There are around 10 more lines in the response, but my current log shows that after "Event.AlarmInpu" there is no output.
When I give the curl command line option
curl http://www.google.com > output.txt
I can find the complete output lines inside the file.
When I use the curl command line tool and I moved the response to an output file, I could see the entire response data. So I can agree that curl command is retrieving the entire response properly. I get the whole response, but the response is longer than my buffer length and hence it is getting truncated.
Do let me know how I can increase my buffer length to get the complete response line.
The code snippet is shown below
typedef struct pageInfo_t {
char *data;
int len;
} pageInfo_t;
static size_t HTTPData(void *buffer, size_t size, size_t nmemb, void *userData)
{
int len = size * nmemb;
pageInfo_t *page = (pageInfo_t *)userData;
page->data = realloc(page->data,page->len + len +1);
memcpy(&page->data[page->len], buffer, len);
page->len += len;
page->data[page->len] = 0;
return len;
}
//Inteface funciton that will recieve web page fom Java
jstring Java_com_samsung_jnitest_MainActivity_JNIGetWebpage( JNIEnv* env,jobject entryObject,jstring webpageJStr)
{
pageInfo_t page;
CURL *curl;
CURLcode res;
char *buffer;
int memorysize = 19189;
page.data = (char *)malloc(16 * memorysize);
page.len = 0;
if (page.data)
memset(page.data, 32, 16 * memorysize);
buffer = (char *)malloc(memorysize);
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, webpage);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &page);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
(*env)->ReleaseStringUTFChars(env, webpageJStr, webpage);
if(response_code == 200)
{
if (buffer)
{
page.data[page.len] = '\0';
sprintf(buffer, "%ld:%s \n", response_code, page.data);
return (*env)->NewStringUTF(env, buffer);
}
}
}
}
Please let me know how to increase the buffer size to hold the complete response lines.
Let me know if I am over complicating the code