我需要使用Java中的HTTP发布登录到网站。HTTP Post登录Java-Android
这里是一个应该被发送到服务器的登录数据:
http://img692.imageshack.us/img692/5412/04a69ba40efe4c8583b84a7.png
我没有任何想法如何做到这一点,可有人能帮助我吗?
我需要使用Java中的HTTP发布登录到网站。HTTP Post登录Java-Android
这里是一个应该被发送到服务器的登录数据:
http://img692.imageshack.us/img692/5412/04a69ba40efe4c8583b84a7.png
我没有任何想法如何做到这一点,可有人能帮助我吗?
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("https://www.example.com/...");
try {
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("email", "login"));
nvps.add(new BasicNameValuePair("password", "pw"));
nvps.add(new BasicNameValuePair("autologin", "true"));
httpost.setEntity(new UrlEncodedFormEntity(nvps));
}
catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
try {
HttpResponse response = httpclient.execute(httpost);
// writing response to log
Log.d("Http Response:", response.toString());
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
}
检查了这一点:http://stackoverflow.com/questions/4543894/android-java-http-post-request – Araw