当我尝试在 url android 中运行一些空格时出现错误,这是代码:
String strUrlLoginFullpath = "";
strUrlLoginFullpath = strUrlMain+"exl?u="+strUser+"&p="+strPass+"&t=1";
URL url = new URL(strUrlLoginFullpath);
publishProgress(40);
//membuka koneksi
URLConnection urlConn = url.openConnection();
urlConn.setConnectTimeout(50000);
urlConn.setReadTimeout(50000);
//digunakan untuk menangkap nilai dari server
BufferedReader in = new BufferedReader(
new InputStreamReader(
urlConn.getInputStream()));
publishProgress(60);
String inputLine;
int i=0;
while ((inputLine = in.readLine()) != null)
{
Log.v("Login",i+", return:" +inputLine+"; url: "+strUrlLoginFullpath);
if(i == 5)
{
Log.v("Login","RESULT >"+i+", return:" +inputLine+"; url: "+strUrlLoginFullpath);
str2 = inputLine;
}
i++;
}
in.close();
publishProgress(80);
publishProgress(100);
}
catch (MalformedURLException e)
{
Log.v("KxL", "MalformedURLException=" + e.toString());
}
catch (IOException e)
{
Log.v("KxL", "IOException=" + e.toString());
}
return null;
}
如您所见..我有进行登录验证的命令, strUrlLoginFullpath = strUrlMain+"exl?u="+strUser+"&p="+strPass+"&t=1";
但条件是strUser有时包含空格,这会使我的程序无法运行。那么如何解决这个问题。?