cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: CURLE_RECV_ERROR

From: dr cs <sproutsnew_at_gmail.com>
Date: Mon, 26 Oct 2009 13:11:55 -0600

On Mon, Oct 26, 2009 at 8:52 AM, Daniel Stenberg <daniel_at_haxx.se> wrote:

> On Fri, 23 Oct 2009, dr cs wrote:
>
> As I'm trying to upload files(using libcurl) to a server via a proxy, I
>> see the following error: CURLE_RECV_ERROR in my application why would I see
>> this error?
>>
>
> How can I get this solved?
>>
>
> Make sure your network is fine. Seriously, the problem is simply that
> libcurl fails when it tries to receive data from the network and why it does
> that is quite impossible for us to tell without a whole lot more info and/or
> experiments.

Let me add my code snippet and try explaining things.
the code works perfectly on a windows machine but not on Linux.

When debugging the connection on my Linux box, I see the following message:

Proxy Settings:

                Proxy IP: 10.103.12.15

                Proxy Port : 8080

                Proxy Username: Rajesh

* About to connect() to 10.103.12.15 port 8080

* Trying 10.103.12.15... * connected

* Connected to 10.103.12.15 (10.103.12.15) port 8080

* Establish HTTP proxy tunnel to upload.bluecoat.com:443

* Proxy auth using (nil) with user 'Rajesh'

< HTTP/1.1 400 Bad Request

HTTP/1.1 400 Bad Request

< Cache-Control: no-cache

Cache-Control: no-cache

< Pragma: no-cache

Pragma: no-cache

< Content-Type: text/html; charset=utf-8

Content-Type: text/html; charset=utf-8

< Proxy-Connection: close

Proxy-Connection: close

< Connection: close

Connection: close

< Content-Length: 691

Content-Length: 691

<

* Closing connection #0

res = failure when receiving data from the peer

HTTP response code = 0

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

Packet capture on my box reveals that :

CONNECT servername:443 HTTP/1.0..(nil)...

Is it expecting some header? If not, why would CURL place a (nil) here?

----------
Code snippet follows:

/* get a curl handle */

  curl = (*fp_curl_easy_init)();

  if(curl) {

    /* we want to use our own read function */

    (*fp_curl_easy_setopt)(curl, CURLOPT_READFUNCTION, read_callback);

     /* enable uploading */

    (*fp_curl_easy_setopt)(curl, CURLOPT_UPLOAD, 1) ;

     /* HTTP PUT please */

    (*fp_curl_easy_setopt)(curl, CURLOPT_PUT, 1);

   /* Uncomment following line when debugging connection */

    (*fp_curl_easy_setopt)(curl, CURLOPT_VERBOSE, 1);

   /* specify target URL, and note that this URL should include a file name,
not only a directory */

    (*fp_curl_easy_setopt)(curl,CURLOPT_URL, m_uploadURL);

#ifdef SKIP_PEER_VERIFICATION

    /*

     * If you want to connect to a site who isn't using a certificate that
is

     * signed by one of the certs in the CA bundle you have, you can skip
the

     * verification of the server's certificate. This makes the connection

     * A LOT LESS SECURE.

     *

     * If you have a CA cert for the server stored someplace else than in
the

     * default bundle, then the CURLOPT_CAPATH option might come handy for

     * you.

     */

    (*fp_curl_easy_setopt)(curl, CURLOPT_SSL_VERIFYPEER, 0);

#endif

#ifdef SKIP_HOSTNAME_VERFICATION

    /*

     * If the site you're connecting to uses a different host name that what

     * they have mentioned in their server certificate's commonName (or

     * subjectAltName) fields, libcurl will refuse to connect. You can skip

     * this check, but this will make the connection less secure.

     */

    (*fp_curl_easy_setopt)(curl, CURLOPT_SSL_VERIFYHOST, 0);

#endif

            if (m_proxyInUse)

            {

                        sprintf(tmpBuf1, "%s:%s", m_proxyIP, m_proxyPort);

                        (*fp_curl_easy_setopt)(curl, CURLOPT_PROXY, tmpBuf1
);

                        sprintf(tmpBuf2, "%s:%s", m_proxyUsername,
m_proxyPassword);

                        (*fp_curl_easy_setopt)(curl, CURLOPT_PROXYUSERPWD,
tmpBuf2 );

                        (*fp_curl_easy_setopt)(curl, CURLOPT_PROXYAUTH,
CURLAUTH_ANY );

                        //(*fp_curl_easy_setopt)(curl,
CURLOPT_HTTPPROXYTUNNEL, TRUE);

                        (*fp_curl_easy_setopt)(curl,
CURLOPT_HTTPPROXYTUNNEL, 1);

            }

            /* now specify which file to upload */

    (*fp_curl_easy_setopt)(curl, CURLOPT_READDATA, hd_src);

    /* provide the size of the upload, we specicially typecast the value

       to curl_off_t since we must be sure to use the correct data size */

    (*fp_curl_easy_setopt)(curl, CURLOPT_INFILESIZE_LARGE,

                     (curl_off_t)filesize);

    /* Now run off and do what you've been told! */

    res = (*fp_curl_easy_perform)(curl);

            (*fp_curl_easy_getinfo)(curl, CURLINFO_RESPONSE_CODE,
&response_code );

            fprintf(stderr, "\nres = %s\nHTTP response code = %ld\n",
(*fp_curl_easy_strerror)(res), response_code);

            if (response_code != 201)

            {

                        returnVal = -1;

            }

    /* always cleanup */

    (*fp_curl_easy_cleanup)(curl);

  }

  fclose(hd_src); /* close the local file */

  (*fp_curl_global_cleanup)();

  return returnVal;

}

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

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-10-26