我正在使用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 datacurl_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 itcurl_setopt($ch,CURLOPT_RETURNTRANSFER, true); UPDATE2:C#Web服務代碼(返回類型為int) try { if (dr.HasRows) { c.Close(); return 0; } else { c.Close(); return 1; } }
檢查Curl從POST返回的值
慕婉清6462132
2021-04-29 17:34:27