1

I get the error "host name may not be null error " in my Android app.

This is my code:

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("http://sub_domain.domain.com/service/api");
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/json");
ResponseHandler responseHandler = new BasicResponseHandler();
    try {
        httpclient.execute(httpost, responseHandler);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

I use a sub-domain so I can't put 'www' in my url because it's another sub domain. I have Internet permission in my manifest file.

Any suggestions? Thanks!

Edit : It's impossible to access to this url with a GET method.

Without '_' in my subdomain, it's okay.

4
  • 1
    check the way url is encoded. any spaces should be eliminated.stackoverflow.com/questions/12537522/…. Similar to your question Commented Feb 27, 2013 at 20:15
  • Have you tried it with a subdomain that doesn't have an underscore in it? They can cause problems. Commented Feb 27, 2013 at 20:26
  • no spaces in my url and with URLEncoder.encode(URL); I have the same issue. Commented Feb 27, 2013 at 20:26
  • I can't. "Users with less than 10 reputation can't answer their own question for 8 hours after asking. " Commented Feb 27, 2013 at 21:34

2 Answers 2

3

Look this link. Apache doesnt support underscore

https://issues.apache.org/jira/browse/HTTPCLIENT-911

Sign up to request clarification or add additional context in comments.

Comments

0

I have encountered Similar Errors when my net connectivity is down in the middle of running of my application. I have Used Async Task And when the Async task doesnt Find the link, /it gives Similar result of Window Leak.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.