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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mapShare challenge 13 68
wordlen challenge 3 46
eclipse formatting 6 38
Any Fantasy Football Brute force AI suggestions? 2 18
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now