【问题标题】:How can I execute a secure HTTP (HTTPS) GET und POST Request in Android?如何在 Android 中执行安全的 HTTP (HTTPS) GET 和 POST 请求?
【发布时间】:2014-03-13 09:05:50
【问题描述】:

在我的应用程序中,我想发出安全的 HTTP 请求(GET、POST),有人可以给我一个简单的例子吗?

【问题讨论】:

    标签: android security https


    【解决方案1】:

    这里是调用执行 http (POST req) 的完整代码

                try {
                ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(3);
    
                nvp.add(new BasicNameValuePair("username", et_email.getText().toString()));
                nvp.add(new BasicNameValuePair("password", et_password.getText().toString()));
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("url to be called");
                httppost.setEntity(new UrlEncodedFormEntity(nvp));
                ResponseHandler<String> responseHandler = new BasicResponseHandler();
                final String responseBody = httpclient.execute(httppost, responseHandler);
                Log.i("response", responseBody);
    
    
    
            } catch (Exception e) {
                Log.i("error1", "" + e.toString());
            }
    

    【讨论】:

    • 如果您不发送任何参数,请勿使用 NVP(名称值对)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多