Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8063225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:57:18+00:00 2026-06-05T10:57:18+00:00

I am using libcurl in my code and the first few attempts of curl_easy_perform()

  • 0

I am using libcurl in my code and the first few attempts of curl_easy_perform() returns proper values but after that I see that the first 800 or so bytes are dropped. The pointer write_data function is passed starts out pointing to the stream after the first 800 bytes or so.

Here is the snippet of code I use –

ctx = curl_easy_init();
curl_easy_setopt(ctx, CURLOPT_POSTFIELDS, bodyData);
curl_easy_setopt(ctx, CURLOPT_URL, serverUrl);
curl_easy_setopt(ctx, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(ctx, CURLOPT_WRITEDATA, response);
res = curl_easy_perform(ctx);
curl_easy_cleanup(ctx);

EDIT: Ok so I see that for some requests, the write_data is called twice for the one curl_easy_perform(). So write_data gets the first x bytes and then reading the remaining in the next time. But my write_data function is overriding the response pointer everytime. How do I know if I need to memcpy or concatenate to the response pointer? I hope I am able to describe the situation properly.

Thanks

P

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:57:21+00:00Added an answer on June 5, 2026 at 10:57 am

    You need to provide a large buffer (your “response” pointer) and every time your write_data function is called you would append more data to the buffer. Your response pointer should probably point to struct, something like this:

    struct myStruct{
        char *buffer; /* remember to malloc this! */
        int size; /* 100000 */
        int used; /* initially 0 */
    };
    typedef struct myStruct myStruct;
    

    Then, on every entry into the write_data function you want to memcpy the supplied data into the buffer after the last position you wrote to (remember, the supplied buffer to write_data is not necessarily null terminated), e.g:

    size_t write_data( char *ptr, size_t size, size_t nmemb, void *userdata)
    {
        myStruct *parseBuf = (myStruct *)userdata;
        int total_size = size * nmemb;
        memcpy(parseBuf->buffer+parseBuf->used, ptr, total_size);
        parseBuf->used += total_size;
        *(parseBuf->buf+parseBuf->used) = 0; /* Add a null terminator on */
        return size * nmemb;
    }
    

    Something like that should do it. (disclaimer: I’ve not bothered to try compiling this, but it should work)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using LibCurl (with SSL) to retrieve XML from an API. But it gives
i am using ruby-1.9.2-p290 and have installed curl, curl-devel, libcurl and libcurl-devel but curb
I'm developing dll that uses libcurl. After adding libcurl.dll and libidn-11.dll to dependences I
I am using libcurl for a small program that gets data from an input
I am trying to do a simple post using libcURL. I noticed that if
my first question here: I am having trouble using libcURL in a c++ project.
I am trying to upload a file to a ftp server using libcurl but
I am using libcurl in my project and it depends on openssl and bunch
I am new using libcurl. I am not understanding clearly how to use it
I am using libcurl I have my downloading of files inside of a class,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.