Android-从服务器获取哈希码

时间:2011-09-25 19:36:10

标签: android post connection

我的应用程序连接到服务器,一旦服务器收到数据,它就会发送一个哈希码作为响应......我的问题是如何获取这个哈希码?

我使用以下代码来发布数据:

 try {
    HttpClient client = new DefaultHttpClient();  
    String postURL = "http://somepostaddress.com";
    HttpPost post = new HttpPost(postURL); 
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("user", "kris"));
        params.add(new BasicNameValuePair("pass", "xyz"));
        UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
        post.setEntity(ent);
        HttpResponse responsePOST = client.execute(post);  
        HttpEntity resEntity = responsePOST.getEntity();  
        if (resEntity != null) {    
            Log.i("RESPONSE",EntityUtils.toString(resEntity));
        }
} catch (Exception e) {
    e.printStackTrace();
}

2 个答案:

答案 0 :(得分:0)

使用EntityUtils.toString(HttpEntity),这会将响应返回为String

答案 1 :(得分:0)

URL url = new URL(url_str);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
InputStream stream = connection.getInputStream();

这就是我为GET所做的,它也适用于POST。