在调用Web服务和接收数据时返回false

时间:2013-10-09 07:47:40

标签: android android-emulator

用户名和密码正确但isResponse()方法返回false

请帮帮我,我们的代码是否正确?

           public boolean isUserAvailable() {
    // Create a new HttpClient and Post Header
    try {
    HttpClient httpclient = new DefaultHttpClient();

    HttpPost httppost = new HttpPost(Commons.IS_USER_AVAILABLE_NEW_REGISTRATION_LINK
                    + edit_USERNAME.getText().toString().trim());


        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();

        if ("available".equalsIgnoreCase(EntityUtils.toString(resEntity))) {
            return true;
        }
    } catch (ClientProtocolException e) {
        Toast.makeText(getApplicationContext(), "error"+e, Toast.LENGTH_LONG).show();

    } catch (IOException e) {
        Toast.makeText(getApplicationContext(), "error"+e, Toast.LENGTH_LONG).show();

    }
    return false;

}

0 个答案:

没有答案