OpenSSL SSL_read: error:1408F119:SSL routines:ssl3_get_record:decryption failed or bad record mac, errno 0 - apache

I am running this piece of code on a Apache server in order to retrieve few zip files.
$ch = curl_init("https://opendata-rncs.inpi.fr/services/diffusion/document/get?
listeIdFichier=" . $listFilesId);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$headers = array(
"Cookie: " . $token,
'login: xxxxxxxxxx',
'password: '. $this->tokenApiInpi,
"Content-Type: application/json",
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$raw_file_data = curl_exec($ch);
if(curl_errno($ch)) {
echo 'error:' . curl_error($ch);
}
curl_close($ch);
On my local machine it works fine, running on a simple symfony server.
But on the Apache production server, I ve got this error:
OpenSSL SSL_read: error:1408F119:SSL
routines:ssl3_get_record:decryption failed or bad record mac, errno 0
Sometimes it works, but it's rare.
OpenSSL 1.1.1f 31 Mar 2020
cURL Information => 7.68.0
curl_getInfo()
array:37 [
"url" => "https://opendata-rncs.inpi.fr/services/diffusion/document/get?listeIdFichier=229514679,230627776,222612310,233647858"
"content_type" => "application/zip"
"http_code" => 200
"header_size" => 705
"request_size" => 291
"filetime" => -1
"ssl_verify_result" => 0
"redirect_count" => 0
"total_time" => 0.462636
"namelookup_time" => 0.003911
"connect_time" => 0.008549
"pretransfer_time" => 0.038412
"size_upload" => 0.0
"size_download" => 703824.0
"speed_download" => 1523428.0
"speed_upload" => 0.0
"download_content_length" => 5362987.0
"upload_content_length" => -1.0
"starttransfer_time" => 0.430148
"redirect_time" => 0.0
"redirect_url" => ""
"primary_ip" => "81.252.220.78"
"certinfo" => []
"primary_port" => 443
"local_ip" => "10.1.2.7"
"local_port" => 53494
"http_version" => 2
"protocol" => 2
"ssl_verifyresult" => 0
"scheme" => "HTTPS"
"appconnect_time_us" => 38371
"connect_time_us" => 8549
"namelookup_time_us" => 3911
"pretransfer_time_us" => 38412
"redirect_time_us" => 0
"starttransfer_time_us" => 430148
"total_time_us" => 462636
]

Related

Upload file using Guzzle 6 to ebay FEED_API endpoint

I'm tryng to upoad e file with ebay FEED_API using Guzzle 6.5 for FILE-EXCHANGE migration to REST API:
$client = new GuzzleHttp\Client(['base_uri' => 'https://api.ebay.com']);
$client->request('POST', '/sell/feed/v1/task/task-40-XXXXXXXXXX/upload_file', [
'headers' => [
'Authorization' => 'Bearer ' . $this->getToken($ebayStore),
'Content-Type' => 'multipart/form-data'
],
'multipart' => [
[
'name' => 'fileName',
'contents' => basename(/path/to/file)
],
[
'name' => 'name',
'contents' => 'file'
],
[
'name' => 'type',
'contents' => 'form-data'
],
[
'name' => 'file',
'contents' => fopen(/path/to/file, 'r'),
'filename' => basename(/path/to/file)
]
]
]);
but i get the following error:
[errors] => Array
(
[0] => stdClass Object
(
[errorId] => 2003
[domain] => ACCESS
[category] => APPLICATION
[message] => Internal error
[longMessage] => There was a problem with an eBay internal system or process. Contact eBay developer support for assistance
[parameters] => Array
(
[0] => stdClass Object
(
[name] => code
[value] => 400
)
[1] => stdClass Object
(
[name] => message
[value] => HTTP 400 Bad Request
)
)
)
)
but if i try to upload the file by cli using curl it works:
curl -g -k -X POST "https://api.ebay.com/sell/feed/v1/task/task-40-XXXXXXXXXX/upload_file" -H "Content-Type: multipart/form-data" -H "Authorization: Bearer v^1.1#i^1#r^0#f^0#p^3#I^3#t..." -i -F "file=#/path/to/file"
It seems api endpoint does not recognize the file associated with the form when i'm using guzzle for the request.
Where am i wrong?
--- EDIT ---
even so it works:
$headers = [
'Authorization:Bearer ' . $this->getToken($ebayStore),
'Content-Type:multipart/form-data'
];
$formData = [
'fileName' => basename($file),
'name' => 'file',
'type' => 'form-data',
'file' => curl_file_create($file)
];
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, self::API_REQUEST_URI.$taskid.'/upload_file');
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_MAXREDIRS , 10);
curl_setopt($connection, CURLOPT_HEADER, 1);
curl_setopt($connection, CURLINFO_HEADER_OUT, true);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $formData);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
My mistake was to manually insert the content-type in the headers.
This is my working code:
My mistake was to manually insert the content-type in the headers.
This is my working code:
$client = new GuzzleHttp\Client(['base_uri' => 'https://api.ebay.com']);
$client->request('POST', '/sell/feed/v1/task/task-40-XXXXXXXXXX/upload_file', [
'headers' => [
'Authorization' => 'Bearer ' . $this->getToken($ebayStore)
],
'multipart' => [
[
'name' => 'file',
'contents' => fopen($file, 'r'),
'filename' => basename($file),
'headers' => [
'Content-Disposition' => 'form-data; name="file"; fileName="'.basename($file).'"; type="form-data"'
]
]
]
]);

Trouble Connecting with BigCommerce API

I'm using the following to try and test a GET request on the BigCommerce API locally, but I'm getting a "Failed to connect to api.bigcommerce.com port 443: Connection refused". Any help would be appreciated. Thanks in advance.
$api_url = 'https://api.bigcommerce.com/stores/STORE-HASH/v3/customers';
$headers = array(
"Accept: application/json",
"Content-Type: application/json",
"X-Auth-Client: xxxxxxxx",
"X-Auth-Token:xxxxxxxx"
);
$chbig = curl_init();
curl_setopt($chbig, CURLOPT_URL, $api_url);
curl_setopt($chbig, CURLOPT_TIMEOUT, 60);
curl_setopt($chbig, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $chbig, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $chbig, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $chbig, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec($chbig); //execute request
$http_status = (string) curl_getinfo($chbig, CURLINFO_HTTP_CODE);
if(curl_errno($chbig))
{
echo 'Curl error: ' . curl_error($chbig);
}
curl_close($chbig);
echo "<pre>";
print_r($http_status);
print_r($result);```
I really like to use Postman for testing out my API requests. You may want to download that as well, if you have not already.
Here is the code that I am using to connect to my customers
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.bigcommerce.com/stores/{STORE_HASH}/v3/customers",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"X-Auth-Token: {TOKEN}",
"X-Auth-Client:{CLIENT_ID}"
),
));
$response = curl_exec($curl); // makes the request
curl_close($curl);
echo $response;
You may be having issues due to the Accept and/or Content-type headers. I would remove those headers and only use the 'X-Auth-Token' and 'X-Auth-Client' headers for GET requests. Good luck!

eBay Sandbox API | Guest Place order | Error: empty reply from server

I am using eBay Sandbox API to place the order, I have generated the session id and pass to this url https://api.sandbox.ebay.com/buy/order/v1/guest_checkout_session/{session_id}/place_order
My php curl is
$header = array('Accept: application/json',
'Authorization: Bearer '.$authToken,
'Content-Type: application/json',
'X-EBAY-C-ENDUSERCTX:affiliateCampaignId=<ePNCampaignId>,affiliateReferenceId=<referenceId>'
);
$placeOrderUrl = "https://api.sandbox.ebay.com/buy/order/v1/guest_checkout_session/{checkoutSessionId}/place_order";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($placeOrderUrl));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$response = curl_exec($ch);
$information = curl_getinfo($ch);
print_r($information);
echo '<br/>';
echo 'Error Code '.curl_errno($ch).'<br/>';
if(curl_errno($ch)){
echo "ERROR:".curl_error($ch);
}
curl_close($ch);
echo '<br/>';
print_r(json_decode($response,true));
but i am getting the error
Error Code 52
ERROR:Empty reply from server
and here is the output array
Array(
[url] => https://api.sandbox.ebay.com/buy/order/v1/guest_checkout_session/v1|5000704767|133511112/place_order
[content_type] =>
[http_code] => 100
[header_size] => 25
[request_size] => 2146
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.314586
[namelookup_time] => 2.3E-5
[connect_time] => 0.073967
[pretransfer_time] => 0.236347
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0.314579
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 66.135.212.84
[certinfo] => Array ()
[primary_port] => 443
[local_ip] => 198.71.236.80
[local_port] => 37903
[request_header] => POST /buy/order/v1/guest_checkout_session/v1|5000704767|133511112/place_order HTTP/1.Host: api.sandbox.ebay.comAccept: application/json
Authorization: Bearer {token}
Content-Type: application/json
X-EBAY-C-ENDUSERCTX:affiliateCampaignId=,affiliateReferenceId=
Expect: 100-continue)
You have to urlencode the sessionId: v1|5000704767|133511112 should be v1%7C5000704767%7C133511112

Bigcommerce php api returning null on initial app install

I'm trying to do initial install of a BigCommerce draft app for oAuth access to api using the official Bigcommerce php library.
For some reason no matter what I do I get null back from a post to BigCommerce api. Can anyone see anything that could be causing this?
Thanks for any advice
<?php
require_once ('vendor/autoload.php');
use Bigcommerce\Api\Connection as Connection;
use Bigcommerce\Api\Client as Bigcommerce;
error_reporting(E_ALL);
ini_set('display_errors', 'on');
$client_id = "*******";
$client_secret = "*******";
if (count($_GET)) {
$code = $_GET['code'];
$context = $_GET['context'];
$scope = $_GET['scope'];
$url = "https://login.bigcommerce.com/oauth2/token";
$connection = new Connection();
$connection->useUrlencoded();
$connection->verifyPeer(false);
$response = $connection->post($url, array(
"client_id" => $client_id,
"client_secret" => $client_secret,
"redirect_uri" => "https://www.*******.com/bc-auth.php",
"grant_type" => "authorization_code",
"code" => $code,
"scope" => $scope,
"context" => $context));
if (is_null($response)) {
print "Last Error:\n";
print "<pre>";
print_r(Bigcommerce::getLastError());
print "</pre>";
exit();
}
$token = $response->access_token;
die($token); // this is just for testing
}
Try making your own POST request via cURL, papi..
// Prepare POST Data:
$postFields = array(
'client_id' => urlencode($client_id),
'client_secret' => urlencode($client_secret),
'code' => urlencode($code),
'scope' => urlencode($scope),
'grant_type' => urlencode('authorization_code'),
'redirect_uri' => urlencode("https://www.*******.com/bc-auth.php"),
'context' => urlencode($context)
);
// Format data for Post:
$fields_string = '';
foreach($postFields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string, '&');
$postFields = $fields_string; // Single URL string of post fields
unset($fields_string);
// ** Curl Config **//
$ch = curl_init(); //open connection
curl_setopt($ch, CURLOPT_URL, "https://login.bigcommerce.com/oauth2/token");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($ch)); // execute post! & assign response
curl_close($ch); // close connection
Removing and inserting it instead of this code:
$connection = new Connection();
$connection->useUrlencoded();
$connection->verifyPeer(false);
$response = $connection->post($url, array(
"client_id" => $client_id,
"client_secret" => $client_secret,
"redirect_uri" => "https://www.*******.com/bc-auth.php",
"grant_type" => "authorization_code",
"code" => $code,
"scope" => $scope,
"context" => $context));

Parse a json array in PHP to get the required values

I am using a API provided by this website
http://pnrapi.alagu.net/
By using this API, we can get PNR status of our indian railways.
I am using CURL to make a call and get the page content which is something like this, in an array format:
Array ( [url] => http://pnrapi.alagu.net/api/v1.0/pnr/4563869832 [content_type] => application/json;charset=utf-8 [http_code] => 200 [header_size] => 185 [request_size] => 130 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 2.906 [namelookup_time] => 0 [connect_time] => 0.312 [pretransfer_time] => 0.312 [size_upload] => 0 [size_download] => 548 [speed_download] => 188 [speed_upload] => 0 [download_content_length] => 548 [upload_content_length] => 0 [starttransfer_time] => 2.906 [redirect_time] => 0 [certinfo] => Array ( ) [primary_ip] => 50.57.204.234 [primary_port] => 80 [local_ip] => 192.168.1.10 [local_port] => 60105 [redirect_url] => [errno] => 0 [errmsg] => [content] => {"status":"OK","data":{"train_number":"16178","chart_prepared":false,"pnr_number":"4563869832","train_name":"ROCKFORT EXPRES","travel_date":{"timestamp":1369506600,"date":"26-5-2013"},"from":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20"},"to":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"alight":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"board":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20","timestamp":1369587000},"class":"2A","passenger":[{"seat_number":"W/L 39,RLGN","status":"W/L 27"}]}} )
but when I go to the URL http://pnrapi.alagu.net/api/v1.0/pnr/4563869832 , it gives me output as shown below:
{"status":"OK","data":{"train_number":"16178","chart_prepared":false,"pnr_number":"4563869832","train_name":"ROCKFORT EXPRES","travel_date":{"timestamp":1369506600,"date":"26-5-2013"},"from":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20"},"to":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"alight":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"board":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20","timestamp":1369587000},"class":"2A","passenger":[{"seat_number":"W/L 39,RLGN","status":"W/L 27"}]}}
Now, it seems that output on my web page with curl have got some extra text which is in the start as you can see both the outputs above.
Well, my question is, how can I get the values from above array.
I am talking about the array output which I'm getting on my page using CURL, which looks like this:
Array (
[url] => http://pnrapi.alagu.net/api/v1.0/pnr/4563869832
[content_type] => application/json;charset=utf-8
[http_code] => 200
[header_size] => 185
[request_size] => 130
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 2.906
[namelookup_time] => 0
[connect_time] => 0.312
[pretransfer_time] => 0.312
[size_upload] => 0
[size_download] => 548
[speed_download] => 188
[speed_upload] => 0
[download_content_length] => 548
[upload_content_length] => 0
[starttransfer_time] => 2.906
[redirect_time] => 0
[certinfo] => Array ( )
[primary_ip] => 50.57.204.234
[primary_port] => 80
[local_ip] => 192.168.1.10
[local_port] => 60105
[redirect_url] =>
[errno] => 0
[errmsg] => [content] => {"status":"OK","data":{"train_number":"16178","chart_prepared":false,"pnr_number":"4563869832","train_name":"ROCKFORT EXPRES","travel_date":{"timestamp":1369506600,"date":"26-5-2013"},"from":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20"},"to":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"alight":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},"board":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20","timestamp":1369587000},"class":"2A","passenger":[{"seat_number":"W/L 39,RLGN","status":"W/L 27"}]}} )
Code in my PHP page is:
<?php
function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
$pnr = get_web_page('http://pnrapi.alagu.net/api/v1.0/pnr/4563869832');
echo "<code>";
print_r($pnr);
echo "</code>";
?>
I only need the values under "content" which are train number, train name, travel date etc.
So, what would be best way to extract this information into each variable?
Like I want it like this:
$train_no = [some code];
$train_name = [some_code];
and so on...
Thanks in advance.
I tried this:
echo $pnr['content'];
and the output I got is:
{"status":"OK",
"data":"train_number":"16178",
"chart_prepared":false,
"pnr_number":"4563869832",
"train_name":"ROCKFORT EXPRES",
"travel_date":{"timestamp":1369506600,"date":"26-5-2013"},
"from":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20"},
"to":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},
"alight":{"code":"MS","name":"CHENNAI EGMORE","time":"05:15"},
"board":{"code":"TPJ","name":"TIRUCHIRAPPALLI JUNCTION","time":"22:20","timestamp":1369587000},
"class":"2A","passenger":[{"seat_number":"W/L 39,RLGN","status":"W/L 27"}]}}
Now can any one give me an idea about how can I fetch unique values from above array?
I'm not sure where the JSON string is. But let's say it's the $pnr variable.
$json = json_decode($pnr, true);
$train_no = $json["data"]["train_number"];
$train_name = $json["data"]["train_name"];
Updated:
If you don't need all the other things you can do something like the following:
$npr = file_get_contents(url);
and then run the code above.
You're looking through the header, where you should be looking at the content. Return $content instead in your function and then you can parse out the response:
function get_web_page( $url ) {
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = json_decode( curl_exec( $ch ) );
curl_close( $ch );
return array(
'train_no' => $content->data->train_number,
'train_name' => $content->data->train_name,
);
}
$pnr = get_web_page('http://pnrapi.alagu.net/api/v1.0/pnr/4563869832');
echo "<pre>" . print_r($pnr, true) . "</pre>";