HttpClient: Target host must not be null, or set in parameters

If you have the following code failing:

HttpGet httpget = new HttpGet(“”);

Then the error is pretty easy to solve:
The problem is that you have not added a protocol to the URL, so change it to:

HttpGet httpget = new HttpGet(“”);

And then it will work as wanted.

17 replies on “HttpClient: Target host must not be null, or set in parameters”

This still doesn’t work for me.
HttpPost post = new HttpPost(“http://infolintyl.something.xml”); doesn’t work. And I have internet permissions in my manifest.

@ama You will get the same error if you are doing something like:
HttpPost post = new HttpPost(URLEncoder.encode(myUrl));
If you remove URLEncoder.encode, the earror will disappear(if you need to encode the url, try to encode just the query params, not all url).

Hope this helps.

Comments are closed.