Reputation: 397
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. 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,
Upvotes: 1
Views: 1385
Reputation: 1210
You are url encoding the complete url, including http and hostname. 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");
Upvotes: 2
Reputation: 184
the http:// is probably getting encoded try something like String foo = foo.replaceFirst("http://", ""); foo = "http://"+ foo
Upvotes: 0