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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog