你如何实现Android 4.0的宁静,HTTP POST请求(How do you to impl

2019-09-19 09:11发布

因为他们改变了我们做出了最新的Android SDK HTTP请求的方式,我一直没能找到一个教程,说明如何使HTTP POST请求。 特别是对于登录。 所以,我想看到一些代码示例,如何实现一个HTTP POST请求,并与饼干的交易。 如果可能的话,我也希望看到一个代码示例https://security.stackexchange.com/questions/4302/how-to-implement-a-remember-me-on-a-mobile-app谢谢。

Answer 1:

图书馆使用: 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.
                    }
                });
    }
};


文章来源: How do you to implement Android 4.0 Restful, HTTP post request