I try to post data via cURL or file_get_contents
, the problem is when I send data from my local host server to my own server(production server), the data post correctly, but when I try with other server (it's for testing) the data is not posting.
Here's my PHP file to send data:
$json = array(
'Shop' =>$url,
'order_number' => $referencia,
'status' => $status,
'payment' => $t_pago,
'shipping_method' => $carrierData,
'costo_envio' => $costo_envio,
'products' =>$products,
'total_weight' => $orderWeight,
'firstname' => $firstname,
'lastname' => $lastname,
'address1' => $address1,
'address2' => $address2,
'postcode' => $postcode,
'country' => $country,
'city' => $city,
'phone' => $phone,
'email' => $email,
'note' => $orderMessage,
);
if($params['newOrderStatus']->id == 4) {
$data = json_encode($json);
$ch = curl_init('http://api.com/prestashop/shipping.php');
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($ch);
curl_close($ch);
}
This is the code with file_get_content
:
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode( $json ),
'header'=> "Content-Type: application/json
" . "Accept: application/json
"
)
);
$context = stream_context_create( $options );
$response = file_get_contents( $url_99, false, $context );
Here's the code that receive the JSON: code