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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

737 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