2017-09-25 109 views
0

我在我的word新闻站点使用下面的代码。我想通过在我的php代码中调用wcf web服务来改变一些功能。下面是我使用的是给我的错误使用curl时发生500内部服务器错误

$Url = "http://localhost:8080/Service1.svc/checkUseronHealnt"; 
$json = "[{\"MOBILE_NO\":\"8745009403,8745009411\"}]" 
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, $Url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($json)); 
$curl_response = curl_exec($curl); 
if (curl_error($curl)) { 
    echo 'error:' . curl_error($curl); 
} else { 
    echo"Response - " . $curl_response; 
} 
+1

'$ JSON = “[{\” MOBILE_NO \ “:\” 8745009403,8745009411 \ “}]”'分号该行后失踪 –

回答

0

$json = "[{\"MOBILE_NO\":\"8745009403,8745009411\"}]"
;代码后在这里不需要这个
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($json));
json_encode丢失。
除非您提供的代码上方有{,否则最后的}也不需要。

0

$ JSON = “[{\” MOBILE_NO \ “:\” 8745009403,8745009411 \ “}]” - 分号是语句后失踪

从代码中删除多余的花括号。

你的好代码如下

$Url ="http://localhost:8080/Service1.svc/checkUseronHealnt"; 
$json = "[{\"MOBILE_NO\":\"8745009403,8745009411\"}]"; 
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, $Url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($json)); 
$curl_response = curl_exec($curl); 
if(curl_error($curl)) { 
    echo 'error:' . curl_error($curl); 
} 
else { 
    echo"Response - ".$curl_response; 
}   
相关问题