cURL / Mailing Lists / curl-library / Single Mail

curl-library

Post using https -- how can I avoid "Content-Length: 0"?

From: Jeff Pratt <jeff.pratt_at_visionstarllc.com>
Date: Tue, 13 Mar 2012 14:57:50 -0700

Hello!

I'm rather new to libcurl.  I need to communicate with a server that
wants https, but they don't really do authentication (or so they say).
It appears that I'm connecting to the site successfully but sending
only a header:

* About to connect() to xxxxx.xxx.com.xx port 443 (#0)
*   Trying ###.##.###.###...
* connected
* Connected to xxxxx.xxx.com.xx (###.##.###.###) port 443 (#0)
* SSL connection using AES128-SHA
* Server certificate:
*        subject:  ....
*        start date: 2011-03-31 21:41:06 GMT
*        expire date: 2014-05-28 06:07:02 GMT
*        subjectAltName: .....
*        issuer: C=xx; ST=xxxxxx; L=xxxxxx; O=xxxxx.com, Inc.; OU=http://
certificates.xxxxx
 serialNumber=xxxxxxxxxx
*        SSL certificate verify result: unable to get local issuer
certificate (20), continuing anyway.
> POST /xxxxxx/Default.aspx HTTP/1.1
Host: xxxxx.xxx.com.xx
Accept: */*
Content-Length: 0

The site does not appear to like this.  The next thing in my libCurl log is:

< HTTP/1.1 200 OK
< Cache-Control: private
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8
< Server: Microsoft-IIS/7.5
< X-AspNet-Version: 2.0.50727
< X-Powered-By: ASP.NET
< Date: Tue, 13 Mar 2012 20:21:22 GMT
<
* Connection #0 to host xxxxx.xxx.com.xx left intact

At this point I bail out (running this in debugger for now) and
execute "curl_easy_cleanup(...);",
after which the log shows

* Closing connection #0

The content I'm trying to send is xml in a flat file... so I'm using
        curl_easy_setopt(curl, CURLOPT_READDATA, pf);
(pf is a FILE *, open for reading; the file size I'm testing with is
3566 bytes).

I've tried addng curl_easy_setopt calls, using either
CURLOPT_POSTFIELDSIZE or CURLOPT_POSTFIELDSIZE_LARGE, to no avail.

I'm using libCurl 7.24.0, downloaded last week.  I'm on an hpux-11 (32-bit) box.

The library calls I'm currently executing, in order, are:

curl_global_init(CURL_GLOBAL_SSL);
CURL *pCurl = curl_easy_init();
curl_easy_setopt(pCurl, CURLOPT_ERRORBUFFER,...
curl_easy_setopt(pCurl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION,...
curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYHOST, 2L);  (tried this with
0L, also, no difference)
curl_easy_setopt(pCurl, CURLOPT_POST, 1L);

Then, since my content is xml, I do:
{
   CURLcode cresult = (CURLcode)0;
   char *ps = calloc(strlen(szContentType)+14+1,1);  /* szContentType
is "text/xml" */
   struct curl_httppost *post=NULL;
   struct curl_httppost *last=NULL;
   struct curl_slist *headers=NULL;
   strcpy(ps, "Content-Type: ");
   strcat(ps, szContentType);
   headers = curl_slist_append(headers, ps);
   curl_formadd(&post, &last, CURLFORM_CONTENTHEADER, headers, CURLFORM_END);
   cresult = curl_easy_setopt(pCurl, CURLOPT_HTTPPOST, post);
   curl_slist_free_all(headers); /* free custom header list */
   curl_formfree(post);         /* free post */
   free(ps);
   if(cresult) /** emit error and exit app here */
}

Then, continuing:
curl_easy_setopt(pCurl, CURLOPT_URL, (the url string));
At this point I discover the file I want to tranmit; fopen it (FILE
*pf, below); and find it's size.  Then:

  ( This is the point at which I attempted to insert
         curl_easy_setopt(pCurl, CURLOPT_POSTFIELDSIZE,
     or  curl_easy_setopt(pCurl, CURLOPT_POSTFIELDSIZE_LARGE,
   to no avail -- since xml can't have embedded nulls, strlen should
also work just fine, so
   I don't think either of the above should be needed; but, with or
without 'em, I get content length: 0 )

curl_easy_setopt(curl, CURLOPT_READDATA, pf);
And finally,
cresult = curl_easy_perform(pCurl);

I'm quite certain that my problem is self-inflicted, probably through
simple ignorance... ;)

But some help would be  truly appreciated as I've been banging my head
on this since yesterday!

--
Best Regards,
Jeff Pratt
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2012-03-13