我从php文件中得到响应字符串“true”... 但是,我的函数总是返回false ...这里是一段代码
public Boolean authorization(String korisnik, String zaporka) {
using (var client = new WebClient())
{
var values = new NameValueCollection();
values["korisnik"] = korisnik;
values["zaporka"] = zaporka;
var response = client.UploadValues("http://localhost/projectX/autorizacija.php", values);
String responseString = Encoding.Default.GetString(response);
System.Diagnostics.Debug.WriteLine(responseString);
if (responseString.Equals("true"))
{
return true;
}
else
{
return false;
}
}
}
答案 0 :(得分:3)
尝试:
if (responseString.Trim().Equals("true", StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
else
{
System.Diagnostics.Debug.WriteLine(responseString);
return false;
}
InvariantCultureIgnoreCase =以语言相关的方式比较字符串,忽略大小写 修剪=删除空格
如果为false,请检查输出值