Reputation: 458
I am posing order-data on ssl means (https) based api via curl, But it return OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104 message.
Here is my test code as per client required json:
$apiKey = "xxxxxx-xxxxxx-xxxxx-xxxxxx-xxxxxx";
$privatekey = "xxxxxx-xxxxxx-xxxxx-xxxxxx-xxxxxx";
$timestamp = date('Y-m-d H:i:s'); // (for example: 2016-07-19 14:05:55)
$signature = hash_hmac('sha1', $timestamp, $apiKey);
$signature = hash_hmac('sha1', $privatekey, $signature);
$postURL = "https://www.compu-cover.com/intelligent-rewards/orders/?OrderNo=123";
$orderInfo['Order'] = array(
"apiKey" => $apiKey,
"privatekey" => $privatekey,
"Signature" => $signature,
"Timestamp" => $timestamp,
"Firstname" => "Ajay",
"Surname" => "Sharma",
"EmailAddress" => "[email protected]",
"DaytimeTel" => "0141798526",
"EveningTel" => "0141798526",
"MobileTel" => "9887654321",
"Address1" => "A-5",
"Address2" => "Jhalana",
"Address3" => "Jaipur",
"Address4" => "Rajasthan",
"County" => "India",
"Postcode" => "302019",
"Cover" => "ADTBL",
"Scheme" => 2,
"Premium" => 5,
"EquipmentQty" => 1,
"EquipmentType1" => "Smartphone",
"EquipmentMake1" => "Moto",
"EquipmentModel1" => "Moto G",
"EquipmentPrice1" => 100
);
$params = json_encode($orderInfo);
$session = curl_init($postURL);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $params);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($session);
if (FALSE === $response) {
var_dump(curl_error($session));
var_dump(curl_errno($session));
}
curl_close($session);
$response = json_decode($response);
var_dump($response);
How to find reason for the failure? What could be the reason for failure? kindly provide your suggestions.
Upvotes: 26
Views: 105310
Reputation: 151
In the standard C library the variable errno
contains the code for what went wrong with the most recent system call. The value of 104 is defined as ECONNRESET
which means "Connection reset by peer".
The error simply means the other side hung up on you, without completing the normal HTTPS protocol and giving back anything in return ... possibly for all sorts of reasons, could be network problems, or server-side program crash, or the other end simply does not like what you did. It's not really related to OpenSSL at all, and to know what caused it you would need access to the server logs.
Upvotes: 15
Reputation: 9
Mostly this will happen if you dont have proper Internet connection. Try is once again, it worked for me
Upvotes: -1
Reputation: 19
I was also getting the error while posting the data to a domain
OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104
I got a solution, as mentioned by LazyBrush, you can set the user agents in curl as per following:
$data_string_ary = array(SOME ARRAY INDEXES);
$data_string = json_encode($data_string_ary);
$url = 'someserver.com/somepage.html';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla Chrome Safari');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: YOUR AUTHORIZATION CODE'
));
$result = curl_exec($ch);
curl_close($ch);
return $result;
It works like a charm for me. Hope this will help for you too.
Upvotes: 0
Reputation: 373
I also realized was missing post data information. After doing so everything worked as expected
Upvotes: 0
Reputation: 460
There are probably many reasons you might get this.
For me, I got this because I was using curl and the web site I was accessing didn't like curl being used. I fixed this with:
curl -A "Mozilla Chrome Safari" someserver.com/somepage.html
This tells curl to say to the server, 'hey I'm a browser'. You can use your favourite browser to get a nicer newer string, go to the browser developer console typically under 'network' you can see individual request items and there you can get the string your current browser sends as the 'user-agent'.
The reason why a website would do this is your typical customer doesn't use curl. Best case a curl will be a bot using up server resource, worst case it's an evil hacker.
Upvotes: 3
Reputation: 5274
I've received this error, and gotten around it simply by waiting a half hour and trying again.
Upvotes: 2
Reputation: 507
I had same issue.
OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104
I guessed the error was regarded openssl or etc. But, it was not.
In my case, one of POST parameters was wrong value. (something like OTP code) And I resolved it finally.
Upvotes: 1