Php卷曲发布数据参数有时发送空

问题描述:

我试图用三个参数调用服务:uri,代码和类型。但有时“type”参数发布为空,有时发布正确。所以服务电话有时会成功,有时会失败。我不改变任何东西,但参数“类型”有时是空的。我怎么解决这个问题 ?Php卷曲发布数据参数有时发送空

$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; 
} 
+0

你能帮忙吗?堆栈溢出取决于每个人分享他们的知识。如果你能回答这个问题,请做! – stef

http_build_query将删除空值..看到第一个注释:http://php.net/manual/en/function.http-build-query.php

+0

我不发送空值。它总是充满。但它不起作用。 – stef

+0

以及它的东西来看看,因为我们无法看到'$ type'值是如何填充的..你说它是空的,所以我去了.. – Rick