你怎么实现Android 4.0的宁静,HTTP POST请求 [英] How do you to implement Android 4.0 Restful, HTTP post request

查看:198
本文介绍了你怎么实现Android 4.0的宁静,HTTP POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于他们改变了我们做出了最新的Andr​​oid SDK的HTTP请求的方式,我一直没能找到一个教程,说明如何使HTTP POST请求。特别是对于登录。所以,我想看到​​一些code例子来说明如何实现HTTP POST请求,并与饼干的交易。如果可能的话,我也希望看到一个code例如<一个href=\"http://security.stackexchange.com/questions/4302/how-to-implement-a-remember-me-on-a-mobile-app\">http://security.stackexchange.com/questions/4302/how-to-implement-a-remember-me-on-a-mobile-app谢谢你。

Since they changed the way we make HTTP request in the latest Android SDK, I have not been able to find a tutorial that shows how to make HTTP post request. Especially for login. So I would like to see a some code examples that show how to implement an HTTP post request, and deals with the cookies. And if possible, I would also like to see a code example for http://security.stackexchange.com/questions/4302/how-to-implement-a-remember-me-on-a-mobile-app Thank you.

推荐答案

图书馆使用:的http:// loopj.com/android-async-http/

private OnClickListener login = new OnClickListener() {

    public void onClick(View view) {

        AsyncHttpClient myClient = new AsyncHttpClient();
        myClient.get(URL, null);
        myClient.setCookieStore(myCookieStore);
        myClient.setCookieStore(myCookieStore);
        String username = "";
        String password = "";
        RequestParams params1 = new RequestParams();
        params1.put("username", username);
        params1.put("password", password);
        pd = ProgressDialog.show(this, "", "Signing In...");
        myClient.post(URL, params1,
                new AsyncHttpResponseHandler() {
                    @Override
                    public void onSuccess(String response) {
                        System.out.println("response" + response);
                        pd.dismiss();
                        if (response.contains("<!--Authorized-->")) {
                        }
                        else {
                            pd.dismiss();
                            Context mContext = SigninActivity.this;
                            notMatchDialog = new Dialog(mContext);
                            notMatchDialog.setContentView(R.layout.loginfaileddialoglayout);
                            notMatchDialog.setTitle("Login failed");
                            dismissDialogButton = (Button) notMatchDialog.findViewById(R.id.dismissDialogButton);
                            dismissDialogButton.setOnClickListener(dismissDialog);
                            notMatchDialog.show();
                        }
                    }

                    @Override
                    public void onFailure(Throwable e, String response) {
                        // TODO Need to figure out different failures and try to help the user.
                    }
                });
    }
};

这篇关于你怎么实现Android 4.0的宁静,HTTP POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆