dpqmu84646 2016-04-14 23:19
浏览 35

使用Curl和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.

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

  • 写回答

1条回答 默认 最新

  • dounei5721 2016-04-14 23:34
    关注

    Make sure allow_url_fopen is set to 1 in your php.ini configuration file. You can view the current php.ini configuration by using the function 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.

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?