您好我在Android中执行网址有问题,我确信它与方括号有关,但我找不到任何解决方案。欢迎大家提出意见。
protected String doInBackground(String... arg0) {
try {
int indexdevice = 12;
String uuu = URLEncoder.encode ("http://<ipaddress>/ZWaveAPI/Run/devices[2].instances[0].commandClasses[0x25].Set(255)", "UTF-8");
HttpClient Client = new DefaultHttpClient();
String SetServerString = "";
HttpGet httpget = new HttpGet(uuu);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
SetServerString = Client.execute(httpget,responseHandler);
Log.v("NAS", "--------- amount is " + SetServerString);
}
catch (Exception ex)
{
Log.v("NAS",String.valueOf(ex));
}
我得到的错误是:
07-08 12:37:33.970: V/NAS(1800): java.lang.IllegalStateException:
Target host must not be null, or set in parameters. scheme=null, host=null,
答案 0 :(得分:2)
您正在编码完整网址的网址,包括http和主机名。那不会奏效。只需在主机地址之后对部件进行编码:
String uuu = "http://<ipaddress>/"+URLEncoder.encode ("ZWaveAPI/Run/devices[2].instances[0].commandClasses[0x25].Set(255)", "UTF-8");
答案 1 :(得分:0)
http://可能正在编码尝试类似的东西 String foo = foo.replaceFirst(“http://”,“”); foo =“http://”+ foo