在我的应用程序中,我想制作安全的HTTP请求(GET,POST),有人可以给我一个简单的例子吗?
答案 0 :(得分:0)
以下是调用执行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());
}