android post issue, why I receive “No route to host”

大憨熊 提交于 2019-12-24 00:16:35

问题


Anybody can help me? When calling HttpResponse response = client.execute(request);

It throws an IOException, which shows "No route to host".

HttpClient client = new DefaultHttpClient();   
HttpPost request = new HttpPost(urlstr.toString());             

List<NameValuePair> postParams = new ArrayList<NameValuePair>();  
postParams.add(new BasicNameValuePair("Login_User_Name", namestr));  
postParams.add(new BasicNameValuePair("Login_User_Password", passwordstr));          
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParams, HTTP.UTF_8);  
request.setEntity(formEntity);  
HttpResponse response = client.execute(request); 

my web soucecode is below

<div class="S-Login" id="S-Login">
    <div class="h" JNetDriftBar="title">
        <span>
                    </span>
    </div>
    <div class="lt" Lge="Login_User_Name"></div>
    <div class="ln">
        <div class="N-Ipt">
            <div class="Nir"></div>
            <div class="Nil"></div>
            <div class="Nic">
                <input type="text" id="Login_User_Name" JNetDriftBar=":focus" value="" maxlength="40" />
            </div>
        </div>
    </div>
    <div class="lt" Lge="Login_User_Password"></div>
    <div class="ln">
        <div class="N-Ipt">
            <div class="Nir"></div>
            <div class="Nil"></div>
            <div class="Nic">
                <input type="password" id="Login_User_Password" value="" maxlength="40" />
            </div>
        </div>
    </div>
    <div class="lt" Lge="Login_Language"></div>
    <div class="ln" style="text-align:left;">
        <div class="N-Select">
            <div class="N-Ipt">
                <div class="Nir"></div>
                <div class="Nil"></div>
                <div class="Nic">
                    <input type="text" readonly="readonly" id="Login_Language" value="" />
                </div>
            </div>
            <div class="NOpt Nc Lg" id="Login-allLanCot">

            </div>
        </div>
    </div>
    <div class="lt"></div>
    <div class="ln">
        <a href="javascript:;" hidefocus="true" class="N-Btn-1" onmousedown="$$.md(this,'N-Btn-1dw',event);" onmouseup="$$.mu(this,'N-Btn-1dw',event);" Lge="Login_Enter" onclick="Entry.submit();"></a>
    </div>
</div>

回答1:


Either the domain name in the URL is invalid (does not exist), you have no network connection, or your DNS server is incorrectly set. Verify that you can browse to the URL in the Android browser.

EDIT: also, make sure you have the INTERNET permission. Add

<uses-permission android:name="android.permission.INTERNET" />

to your AndroidManifest.xml.



来源:https://stackoverflow.com/questions/6645555/android-post-issue-why-i-receive-no-route-to-host

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