I was trying to call some RESTFull API functions that were over https using php and curl. There was something wrong with it that was preventing me from communicating with remote server. I was getting this error:
GnuTLS recv error (-9): A TLS packet with unexpected length was received.
The problem is that cURL has not been configured to trust the server’s HTTPS certificate. There are two fixes available to this issue one that is quick and easy and one that's a bit complicated but more proper.
To resolve this issue you can simply tell the curl to skip the server's certificate verifaction by adding these lines to your php code:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSLVERSION, 3);
This fix will remove that error but you should consider the proper fix that has been suggested by Peter Ching if you are concerned about the security of the data being sent and received.