我正在使用curl调用远程C#Web服务。该服务返回0或1,具体取决于通过检查数据库传递给它的值。当我使用echo $result该值时,将正确打印。但是,当我尝试比较输出值时,代码不起作用。请指教
$result = curl_exec($ch);
if ( $result == 0 )
{
echo("Valid");
}
else
{
echo("Invalid");
}
VarDump是---> string(103)“ 0”
更新:
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
UPDATE2:C#Web服务代码(返回类型为int)
try { if (dr.HasRows) { c.Close(); return 0; } else { c.Close(); return 1; } }