HTTP Client in Apache return "Target host must not be null"

Posted on 2009-06-29
Last Modified: 2013-12-06
Dear experts,
I am using Apache HTTP client library for Android emulator.

However whenever I enter e.g "" or "", it always return error "Target host must not be null"
But when i convert into IP Address, all works well.
Would you be able to advice?

public void run() {
			Log.i("GList", "downloadProcess run()");
			props = new Properties();
			try {
				String url;
				url = ""; //THIS IS FAILED
				//url = ""; // THIS IS OK
				HttpManager.doGet(url, props);
			} catch (Exception e) {
				// TODO Auto-generated catch block
			// TODO Auto-generated method stub

Open in new window

Question by:isuhendro
  • 3
  • 2
LVL 86

Expert Comment

ID: 24743483
>>HttpManager.doGet(url, props);

What's that? It's not Apache HttpClient..

Author Comment

ID: 24743532
HttpManager just a wrapper of Apache HTTP client, please refer to the static method inside HttpManager below.
	public static String doGet (String serviceEndpoint, Properties props) throws Exception
		HttpClient httpClient = new DefaultHttpClient();
		StringBuilder uriBuilder = new StringBuilder(serviceEndpoint);
		StringBuffer sbResponse = new StringBuffer ();		
		Enumeration<Object> enumProps = props.keys();
		String key, value = null;
		if (enumProps.hasMoreElements()) uriBuilder.append('?');
		while (enumProps.hasMoreElements())
			key = (String)enumProps.nextElement();
			value = (String)props.get(key);
		HttpGet request = new HttpGet(uriBuilder.toString());
	HttpResponse response = httpClient.execute(request);

Open in new window

LVL 86

Accepted Solution

CEHJ earned 125 total points
ID: 24743600
>>But when i convert into IP Address, all works well.

Sounds like a DNS error. Have you tried running your code on another network?

Author Closing Comment

ID: 31598185
hi CEHJ,

thank you for your suggestion.
somehow this line gave invalid form URL
LVL 86

Expert Comment

ID: 24949148

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet requestdispatcher include and forward differences 1 39
servlet example 17 51
Java 8 to Java 6 8 20
American Express @Work site and Java 4 24
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question