I am posting a url with params containg an underscore (_).
sample: http://sdsdsds_asasasahjhd.com/dsdsdsd/login.json?
I am posting it like this:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://sdsdsds_asasasahjhd.com/dsdsdsd/login.json?");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("key1", "value1"));
nameValuePairs.add(new BasicNameValuePair("key2", "value2"));
nameValuePairs
.add(new BasicNameValuePair("key3", "value3"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (Exception e) {
e.printStackTrace();
}
When I am inspecting httpclient.execute(httppost)
I am getting IllegalArgumentException
and in catch in exception details it is telling Host name cannot be null
.
Please specify any solution.
I have gone through some other questions here:
but no use as I am not encoding the whole url.
I have an open-source library with network implementation mechanism. It has just receiver an workaround implementation. All you need it to set the host by reflection in case of troubles:
final URI uriObj = new URI("https", host, path, null, null);
if (uriObj.getHost() == null) {
final Field hostField = URI.class.getDeclaredField("host");
hostField.setAccessible(true);
hostField.set(uriObj, host);
}
return uriObj;
The commit is here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With