douzhu1188 2017-03-17 05:44
浏览 909

Php curl post数据参数有时会发送为空

I am trying to call service with three parameters: uri, code and type. But sometimes "type" parameter posting empty, sometimes posting correct. So service call sometimes successfull, sometimes fail. I don't change anything but parameter "type" sometimes empty. How can ı solve this problem ?

$curl_post_data = array(   
        "uri" => $uri,
        "code" => $code,
        "type" => $type
    );

$post_data = http_build_query($curl_post_data);
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPAUTH, xxx);
curl_setopt($curl, CURLOPT_USERPWD, xxx);
curl_setopt($curl, CURLOPT_PROXY, 'xxx');
curl_setopt($curl, CURLOPT_PROXYUSERPWD, 'xxxx');
curl_setopt($curl, CURLOPT_PROXYPORT, xxx);
curl_setopt($curl, CURLOPT_PROXYAUTH, xxx);
$curl_response = curl_exec($curl);
if (false === $curl_response) {
     return null;
}
  • 写回答

1条回答 默认 最新

  • douyouchou1085 2017-03-17 05:48
    关注

    http_build_query will remove null values.. see first comment: http://php.net/manual/en/function.http-build-query.php

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?