有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android httpclient登录到Rails服务器

我开始学习如何制作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;
    }
}

共 (0) 个答案