?
Solved

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

Posted on 2009-06-29
5
Medium Priority
?
1,686 Views
Last Modified: 2013-12-06
Dear experts,
I am using Apache HTTP client library for Android emulator.
http://hc.apache.org/httpcomponents-client/httpclient/apidocs/org/apache/http/client/package-summary.html

However whenever I enter e.g "www.google.com" or "http://www.google.com", 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?

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

Open in new window

0
Comment
Question by:isuhendro
[X]
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
5 Comments
 
LVL 86

Expert Comment

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

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

Author Comment

by:isuhendro
ID: 24743532
Hi CEHJ,
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);
			uriBuilder.append(key);
			uriBuilder.append('=');
			uriBuilder.append(java.net.URLEncoder.encode(value));
			uriBuilder.append('&');			
		}
		HttpGet request = new HttpGet(uriBuilder.toString());
		
	HttpResponse response = httpClient.execute(request);
 
		

Open in new window

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 375 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?
0
 

Author Closing Comment

by:isuhendro
ID: 31598185
hi CEHJ,

thank you for your suggestion.
somehow this line java.net.URLEncoder gave invalid form URL
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24949148
:-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 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