Java tutorial
//package com.java2s; import java.io.IOException; import java.io.UnsupportedEncodingException; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import android.util.Log; public class Main { private static String TAG = "XJTUAuthUtils"; public static boolean logout() { String baseUrl = "http://10.6.8.2/cgi-bin/srun_portal?action=logout&ac_id=1"; try { HttpGet getMethod = new HttpGet(baseUrl); getMethod.addHeader("Accept", "*/*"); //getMethod.addHeader("Accept-Language", "zh-cn"); //getMethod.addHeader("Referer", "http://202.117.2.41/index.html"); //getMethod.addHeader("Content-Type", "application/x-www-form-urlencoded"); //getMethod.addHeader("Accept-Encoding", "gzip, deflate"); //getMethod.addHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"); getMethod.addHeader("Host", "10.6.8.2"); //getMethod.addHeader("DNT", "1"); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(getMethod); Log.i(TAG, "Sending message....."); HttpEntity httpEntity = response.getEntity(); if (response.getStatusLine().getStatusCode() == 200) { String message = EntityUtils.toString(httpEntity); Log.i(TAG, "Logout succeed!!! message=" + message); return true; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.i(TAG, "Logout failed!!!"); return false; } }