2017-09-25 111 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; 
}   
相關問題