host name may not be null error in android

假装没事ソ 提交于 2019-12-13 02:22:51

问题


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.


回答1:


Look this link. Apache doesnt support underscore

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




回答2:


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.



来源:https://stackoverflow.com/questions/15121407/host-name-may-not-be-null-error-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!