你怎么实现Android 4.0的宁静,HTTP POST请求你怎么、宁静、Android、HTTP

2023-09-08 08:49:34 作者:慢性子里的暴脾气

由于他们改变了我们做出了最新的Andr​​oid SDK的HTTP请求的方式,我一直没能找到一个教程,说明如何使HTTP POST请求。特别是对于登录。所以,我想看到​​一些code例子来说明如何实现HTTP POST请求,并与饼干的交易。如果可能的话,我也希望看到一个code例如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.
                    }
                });
    }
};