Java Android httpclient登录到Rails服务器

Java Android httpclient登录到Rails服务器,java,android,ruby-on-rails,Java,Android,Ruby On Rails,我开始学习如何制作Android应用程序。我尝试使用httpclient将我的应用程序连接到rails服务器,但是我不知道如何在应用程序和远程服务器之间连接 这是我代码的一部分,我将“BasicNameValuePair”中的id表单与html id值进行了匹配。请让我知道如何检查登录是否成功 class SendPost extends AsyncTask<Void, Void, String> { protected String doInBackground(Voi

我开始学习如何制作Android应用程序。我尝试使用httpclient将我的应用程序连接到rails服务器,但是我不知道如何在应用程序和远程服务器之间连接

这是我代码的一部分,我将“BasicNameValuePair”中的id表单与html id值进行了匹配。请让我知道如何检查登录是否成功

class SendPost extends AsyncTask<Void, Void, String> 
{

    protected String doInBackground(Void... unused) {
        String content = executeClient();
        return content;
    }

    protected void onPostExecute(String result) {

    }


    public String executeClient() {
        ArrayList<NameValuePair> post = new ArrayList<NameValuePair>();
        post.add(new BasicNameValuePair("user_name", "SallyCook"));
        post.add(new BasicNameValuePair("user_email", "domain@ppls.kr"));
        post.add(new BasicNameValuePair("user_password", "add123456"));
        post.add(new BasicNameValuePair("user_password_confirmation", "add123456"));
        post.add(new BasicNameValuePair("user_phone", "01013089579"));


        HttpClient client = new DefaultHttpClient();
        HttpParams params = client.getParams();
        System.out.println(params);
        HttpConnectionParams.setConnectionTimeout(params, 5000);
        HttpConnectionParams.setSoTimeout(params, 5000);

        HttpPost httpPost = new HttpPost("http://www.ppls.kr/users/sign_up");

        try {
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(post, "UTF-8");
            httpPost.setEntity(entity);
            HttpResponse responsePost = client.execute(httpPost);
            System.out.println(responsePost.getStatusLine());
            HttpEntity resEntity=responsePost.getEntity();


             if (resEntity != null) {
                   Log.w("RESPONSE", EntityUtils.toString(resEntity));
             }
            return EntityUtils.getContentCharSet(entity);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
类SendPost扩展了异步任务
{
受保护字符串DOIN背景(无效…未使用){
字符串内容=executeClient();
返回内容;
}
受保护的void onPostExecute(字符串结果){
}
公共字符串executeClient(){
ArrayList post=新的ArrayList();
post.add(新的BasicNameValuePair(“用户名”、“SallyCook”);
添加(新的BasicNameValuePair(“用户电子邮件”)domain@ppls.kr"));
post.add(新的BasicNameValuePair(“用户密码”,“add123456”);
post.add(新的BasicNameValuePair(“用户密码确认”、“add123456”);
post.add(新的BasicNameValuePair(“用户电话”,“01013089579”));
HttpClient=new DefaultHttpClient();
HttpParams params=client.getParams();
系统输出打印项次(参数);
HttpConnectionParams.setConnectionTimeout(参数,5000);
HttpConnectionParams.setSoTimeout(参数,5000);
HttpPost HttpPost=新的HttpPost(“http://www.ppls.kr/users/sign_up");
试一试{
UrlEncodedFormEntity实体=新的UrlEncodedFormEntity(后“UTF-8”);
httpPost.setEntity(实体);
HttpResponse responsePost=client.execute(httpPost);
System.out.println(responsePost.getStatusLine());
HttpEntity当前状态=responsePost.getEntity();
if(最近性!=null){
Log.w(“RESPONSE”,EntityUtils.toString(resEntity));
}
返回EntityUtils.getContentCharSet(实体);
}捕获(客户端协议例外e){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
返回null;
}
}