I don't know if I've get what you really want to do, but I'm sure that at least, you gonna need some Get/Post operations to execute authentication proccess and retrieve data/informations. Please check the following methods:
public StringBuilder post(String url, List<NameValuePair> nvps) {
try {
HttpPost httppost = new HttpPost(url);
// if there is cookies, set then
if (cookies != null && cookies.size() > 0) {
String cookieString = "";
for (int i = 0; i < cookies.size(); ++i) {
cookieString += cookies.get(i).getName() + "=" + cookies.get(i).getValue() + "; ";
}
cookieString += "domain=" + Constants.BaseUrl + "; " + "path=/";
httppost.addHeader("Cookie", cookieString);
}
// connection timeout options
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, Constants.timeoutConnection);
HttpConnectionParams.setSoTimeout(httpParameters, Constants.timeoutSocket);
// setup the post method
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = httpClient.execute(httppost);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
StringBuilder builder = new StringBuilder();
for (String line = null; (line = reader.readLine()) != null;)
builder.append(line).append("\n");
// set cookies
List<Cookie> incomingCookies = httpClient.getCookieStore().getCookies();
for (int i = 0; incomingCookies != null && i < incomingCookies.size(); i++) {
cookies.add(incomingCookies.get(i));
}
return builder;
} catch (UnsupportedEncodingException e) {
} catch (ClientProtocolException e) {
} catch (IOException e) {
} catch (Exception e) {
}
return null;
}
The above mehod executes a post in the url string parameter, using the pair values nvps as arguments for header. Note that Constants class is the class where you are declaring static strings (such as API entries) for your WebService, and the field cookies is a list of Cookies that gonna hold your session issues. This method will return the result for your POST request as a string builder object. Basically, it is a general-purpose method that can be used in several cases, and you should do little adaptations to fit tasks. This is what you can use to authenticate.
There is another important method, the Http GET:
public StringBuilder get(String url) {
try {
HttpGet httpget = new HttpGet(url);
// if there is cookies, set then
if (cookies != null && cookies.size() > 0) {
String cookieString = "";
for (int i = 0; i < cookies.size(); ++i) {
cookieString += cookies.get(i).getName() + "=" + cookies.get(i).getValue() + "; ";
}
cookieString += "domain=" + Constants.BaseUrl + "; " + "path=/";
httpget.addHeader("Cookie", cookieString);
}
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, Constants.timeoutConnection);
HttpConnectionParams.setSoTimeout(httpParameters, Constants.timeoutSocket);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(httpget);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
StringBuilder builder = new StringBuilder();
for (String line = null; (line = reader.readLine()) != null;)
builder.append(line).append("\n");
// set cookies
List<Cookie> incomingCookies = httpClient.getCookieStore().getCookies();
for (int i = 0; incomingCookies != null && i < incomingCookies.size(); i++) {
cookies.add(incomingCookies.get(i));
}
return builder;
} catch (UnsupportedEncodingException e) {
} catch (ClientProtocolException e) {
} catch (IOException e) {
} catch (Exception e) {
}
return null;
}
This one do similar sequence of steps, but with very different purposes. The goal of this one is to retrieve informations, considering that you already have authenticated or that the auth process is not needed. It returns the requested data as a string builder.
Please, note that besides these methods are very general, you must closely check what is the proccess used in your requested web page. Hope that it helps you in some way! ;-)