cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_easy_perform() failed: Failure when receiving data from the peer

From: Ray Satiro via curl-library <curl-library_at_cool.haxx.se>
Date: Sun, 6 Mar 2016 17:58:32 -0500

On 3/4/2016 4:04 AM, ravi kumar via curl-library wrote:
> Hello sir,
> I am using the following line in my program and getting error, Error
> 411. The request must be chunked or have a content length.
> slist = curl_slist_append(slist,"feed: value");
> curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
> curl_easy_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
> curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
> curl_easy_setopt(curl, CURLOPT_URL, url);
> curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
>
> and when i add in program slist = curl_slist_append(slist,
> "Transfer-Encoding: chunked");
> So, it gives the following error.
> when compiling with gcc -Wall -g test.c -lcurl -o test
> error :
> GnuTLS recv error (-9): A TLS packet with unexpected length was received.
> Closing connection 0
> curl_easy_perform() failed: Failure when receiving data from the peer
> and compiling with gcc test.c $(pkg-config --libs --cflags libcurl)
> -o myprogram
> error:
> SSL read: error:00000000:lib(0):func(0):reason(0), errno 104
> Closing connection 0
> curl_easy_perform() failed: Failure when receiving data from the peer.
> Please let me know where i am doing wrong.
>

I've seen a lot of POST examples on the internets that unnecessarily use
CURLOPT_CUSTOMREQUEST [1] or its command line equivalent -X to set
"POST". It should not be necessary to use CURLOPT_CUSTOMREQUEST to set
POST in most cases. Remove that line and instead use CURLOPT_POST [2].
If you are posting a string you can use CURLOPT_POSTFIELDS [3] which
implies CURLOPT_POST.

   curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "foo=bar&baz=qux");

If your API does not require actual POST content data even though the
method must be POST you can use an empty string which will send a
content length of 0 to indicate you don't have any data:

   curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "");

error 104 is connection reset by peer. When I have seen that error it
has been after SSL negotiation was successful but the server then
terminated the connection before any reply to the request (ie no data
was sent). There's an example of why that may happen at [4] but I think
it is very likely due to your bad request.

Also I recall your API tells you to pass feed as a header string but I'd
check the manual about that, it may mean some type of header in whatever
content you may have to send and not an actual HTTP header line. If you
can't get it working check the manual for a sample request that you can
imitate or ask them.

[1]: https://curl.haxx.se/libcurl/c/CURLOPT_CUSTOMREQUEST.html
[2]: https://curl.haxx.se/libcurl/c/CURLOPT_POST.html
[3]: https://curl.haxx.se/libcurl/c/CURLOPT_POSTFIELDS.html
[4]:
https://drjohnstechtalk.com/blog/2013/07/the-it-detective-agency-strange-ssl-error-explained/

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-03-06