[英]Square brackets causing error in URL string in android
Hi im having a problem with executing a URL in Android, I am sure it is related to the square brackets but I cant find any solution. 嗨,我在Android中执行URL时遇到问题,我确定它与方括号有关,但我找不到任何解决方案。 Any suggestions would be welcome.
欢迎大家提出意见。
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));
}
The error I am getting is: 我得到的错误是:
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,
You are url encoding the complete url, including http and hostname. 您使用url编码完整的url,包括http和主机名。 That won't work.
那行不通。 Just encode the part after the host address:
只需在主机地址后编码部分:
String uuu = "http://<ipaddress>/"+URLEncoder.encode ("ZWaveAPI/Run/devices[2].instances[0].commandClasses[0x25].Set(255)", "UTF-8");
the http:// is probably getting encoded try something like String foo = foo.replaceFirst("http://", ""); http://可能正在编码,请尝试使用类似String foo = foo.replaceFirst(“ http://”,“”); foo = "http://"+ foo
foo =“ http://” + foo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.