简体   繁体   English

使用Curl和file_get_content php发送数据的问题

[英]problems sending data with Curl and file_get_content php

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. 我尝试通过cURL或file_get_contents发布数据,问题是当我从本地主机服务器向我自己的服务器(生产服务器)发送数据时,数据正确发布,但当我尝试使用其他服务器(用于测试)数据时不发布。

Here's my PHP file to send data: 这是我发送数据的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);
}

This is the code with file_get_content : 这是带有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 );

Here's the code that receive the JSON: code 这是接收JSON: 代码的代码

Make sure allow_url_fopen is set to 1 in your php.ini configuration file. 确保php.ini配置文件中的allow_url_fopen设置为1。 You can view the current php.ini configuration by using the function phpinfo(); 您可以使用函数phpinfo();查看当前的php.ini配置phpinfo(); . This variable sets whether PHP is allowed to open files from remote servers, and will block execution of file_get_contents() to remote servers. 此变量设置是否允许PHP从远程服务器打开文件,并阻止将file_get_contents()执行到远程服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM