cURL / Mailing Lists / curl-library / Single Mail

curl-library

Gargbage sent with PUT

From: Robert Kohn <personalrobert_at_gmail.com>
Date: Fri, 23 Sep 2011 13:21:54 -0700

Dear libcurl Developers,

I am trying to implement a simple PUT program (see attached and below).
If you run the program, you will see the following output:

* Connected to madeup.com (208.87.33.151) port 80 (#0)
> PUT / HTTP/1.1
Host: madeup.com
Accept: */*
Content-Length: 46
Content-Length: 46
Expect: 100-continue

Two questions:
  1) What is that 2nd "Content-Length: 46" doing there?
  2) Why does the string "Content-Length: 46" end up in my uploaded PUT
file?

Now look at line 54 in the source code (INFILESIZE_LARGE), currently
commented out. If I un-comment it, my output changes to:
   .
   .
   .
Content-Length: 46
Content-Length: 577733969588518958

And that goofy 2nd "Content-Length" line ends up in my uploaded file!

Help, please!

Thank you.

- Robert

Source code:

#include <string>
#include <string.h>
#include <time.h>
#include <sstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <curl/curl.h>

int main( int argc, char **argv)
{
  std::ostringstream
    length;
  CURL
    *curl;
  struct curl_slist
    *slist;
  int
    ival;
  FILE
    *fp;
  struct stat
    finfo;
  curl_off_t
    fsize;
  const char
    *filenam = "x.x";

  stat( filenam, &finfo);
  fsize = (curl_off_t) finfo.st_size;
  fp = fopen( filenam, "r");

  slist = NULL;

  length << "Content-Length: " << fsize;
  slist = curl_slist_append( slist, length.str().c_str());

  curl = curl_easy_init();
  curl_easy_setopt( curl, CURLOPT_HTTPHEADER, slist);
  curl_easy_setopt( curl, CURLOPT_URL, "http://madeup.com");
  curl_easy_setopt( curl, CURLOPT_UPLOAD, 1L);
  curl_easy_setopt( curl, CURLOPT_PUT, 1L);
  curl_easy_setopt( curl, CURLOPT_INFILESIZE, fsize);
  //curl_easy_setopt( curl, CURLOPT_INFILESIZE_LARGE, fsize);
  curl_easy_setopt( curl, CURLOPT_READDATA, fp);
  curl_easy_setopt( curl, CURLOPT_VERBOSE, 1);
  ival = curl_easy_perform( curl);

  curl_slist_free_all( slist);
  curl_easy_cleanup( curl);
  fclose( fp);

  return 0;
}

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html

  • application/octet-stream attachment: test2.cc
Received on 2011-09-23