cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-tracker mailing list Archives

[ curl-Bugs-1964101 ] problem with callbacks on MSVS 2005

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Fri, 16 May 2008 02:27:28 -0700

Bugs item #1964101, was opened at 2008-05-14 22:19
Message generated for change (Settings changed) made by bagder
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=1964101&group_id=976

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: http
Group: portability problem
>Status: Pending
Resolution: Works For Me
Priority: 5
Private: No
Submitted By: Anthony K (iamgeek)
Assigned to: Daniel Stenberg (bagder)
Summary: problem with callbacks on MSVS 2005

Initial Comment:
/*

Hi.
I have problem with libcurl, at win32 system with curl_formadd and callbacks.

It's modified C code example.
If curl_formadd functions not commented "mycallback" function doesn't executes.
I got this problem on win32 system with MSVS 2005, on Linux/FreeBSD with GCC this code works without any problems.

Thnx
Tony.

*/

#include <stdio.h>
#include <string.h>

#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

size_t mycallback(void * buffer, size_t n, size_t m, void * stream)
{
        char * l = (char*)buffer;
        printf("data: %s \n", l);
        return n;
}

int main(int argc, char *argv[])
{
  CURL *curl;
  CURLcode res;

  struct curl_httppost *formpost=NULL;
  struct curl_httppost *lastptr=NULL;
  struct curl_slist *headerlist=NULL;
  char buf[] = "Expect:";

  curl_global_init(CURL_GLOBAL_ALL);
  
  //curl = curl_easy_init();

  curl_formadd(&formpost,
               &lastptr,
               CURLFORM_COPYNAME, "sendfile",
               CURLFORM_FILE, "postit2.c",
               CURLFORM_END);

  curl_formadd(&formpost,
               &lastptr,
               CURLFORM_COPYNAME, "filename",
               CURLFORM_COPYCONTENTS, "postit2.c",
               CURLFORM_END);

  curl_formadd(&formpost,
               &lastptr,
               CURLFORM_COPYNAME, "submit",
               CURLFORM_COPYCONTENTS, "send",
               CURLFORM_END);

  curl = curl_easy_init();
  /* initalize custom header list (stating that Expect: 100-continue is not
     wanted */
  headerlist = curl_slist_append(headerlist, buf);
  if(curl) {
    /* what URL that receives this POST */
    curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/examplepost.cgi");
    if ( (argc == 2) && (!strcmp(argv[1], "noexpectheader")) )
      /* only disable 100-continue header if explicitly requested */
      curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, mycallback);
    curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, mycallback);
    res = curl_easy_perform(curl);

    /* always cleanup */
    curl_easy_cleanup(curl);

    /* then cleanup the formpost chain */
    curl_formfree(formpost);
    /* free slist */
    curl_slist_free_all (headerlist);
  }
  return 0;
}

----------------------------------------------------------------------

Comment By: Daniel Stenberg (bagder)
Date: 2008-05-14 23:48

Message:
Logged In: YES
user_id=1110
Originator: NO

Uhm, do you even have those files in your local directory? What does
curl_easy_cleanup() actually return?

----------------------------------------------------------------------

Comment By: Daniel Stenberg (bagder)
Date: 2008-05-14 23:46

Message:
Logged In: YES
user_id=1110
Originator: NO

You need to be more specific (like exact libcurl version and preferably
showing us the full request plus actual response); callbacks work for a
large number of people. There's no difference internally for when
delivering data that is a response to a POST than responses to other
methods.

Your write callback function assumes zero terminated data which isn't
delivered and you're posting to a URL that doesn't exist (ie you probably
get a 404 back).

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=1964101&group_id=976
Received on 2008-05-16

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET