1
我試圖通過cURL或file_get_contents
發佈數據,問題是當我從本地主機服務器發送數據到我自己的服務器(生產服務器)時,數據正確地發佈,但是當我嘗試與其他服務器(這是爲了測試)的數據不張貼。用curl和file_get_content發送數據的問題php
這裏是我的PHP文件中發送數據:
$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);
}
這是file_get_content
代碼:
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode($json),
'header'=> "Content-Type: application/json\r\n" . "Accept: application/json\r\n"
)
);
$context = stream_context_create($options);
$response = file_get_contents($url_99, false, $context);
下面是收到JSON代碼:code
我檢查了值並啓用,所以我不明白爲什麼不發送數據 – victor