First of all I CANNOT change that URL.... that said... I have a really dumb problem, I am getting this error:
Caused by: java.lang.IllegalArgumentException: Host name may not be null
in the code below:
URL url = null;
try{
// encodedURL = URLEncoder.encode("elbot_e.csoica.artificial-solutions.com/cgi-bin/elbot.cgi", "UTF-8");
String urlStr = "http://elbot_e.csoica.artificial-solutions.com/cgi-bin/elbot.cgi";
url = new URL(urlStr);
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
url = uri.toURL();
} catch(Exception e) {
}
HttpPost httpPost = new HttpPost(String.valueOf(url));
I have checked if the URL is valid in: http://formvalidation.io/validators/uri/ and I have discovered that the UNDERSCORE_ in the URL is messing things up and I cannot change the URL, who knows a solution or workaround for this?
First, you should not use HttpPost as it's deprecated, instead use HttpURLConnection.
Second, why not use directly the String constructor?
Seems like you are doing a lot of unneeded extra work and introducing some bugs by complicating things too much. The URL looks valid, so that should work.
EDIT:
You can add URL encoding if you have problems with the String: