2016-04-14 112 views
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

回答

0

確保allow_url_fopen是在你的php.ini配置文件中設置爲1。您可以使用功能phpinfo();查看當前的php.ini配置。此變量設置是否允許PHP從遠程服務器打開文件,並將阻止執行file_get_contents()到遠程服務器。

+0

我檢查了值並啓用,所以我不明白爲什麼不發送數據 – victor