This is a follow up question of http://stackoverflow.com/questions/3550593/sending-html-commands-over-httpclient-android , I have successfully POSTed to the server and recieved 200 code but when I attempt to move to another page it does not recognize that I have logged in. I am wondering if it is a session issue or if i need to follow the redirect after the POST. How would I go about following a redirect? Again any help is greatly appreciated. Here is a simple HttpClient / POST app I created from examples in order to help me quickly test any changes.
public class HttpClientTest extends Activity{
HttpClient client = new DefaultHttpClient();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button btnFetch = (Button)findViewById(R.id.button);
final TextView txtResult = (TextView)findViewById(R.id.content);
final Button login = (Button)findViewById(R.id.button2);
btnFetch.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
getRequest(txtResult);
}
});
login.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
try {
login(txtResult);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public void getRequest(TextView txtResult){
HttpGet request = new HttpGet("http://gc.gamestotal.com/i.cfm?f=com_empire&cm=3");
try{
HttpResponse response = client.execute(request);
txtResult.setText(Parser.request(response));
}catch(Exception ex){
txtResult.setText("Failed!");
}
}
public void login(TextView txtResult) throws UnsupportedEncodingException, IOException{
String action = "i.cfm?&1028&p=login&se=4";
String yourServer = "http://gc.gamestotal.com/";
HttpPost post = new HttpPost(yourServer + action);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("nic", "user"));
params.add(new BasicNameValuePair("password", "password"));
params.add(new BasicNameValuePair("server", "4"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
post.setEntity(entity);
try{
HttpResponse response = client.execute(post);
txtResult.setText(response.getEntity().toString());
}catch(Exception ex){
txtResult.setText("Failed!");
}
}
}
I first press the login button on the UI which gives me the Http/1.1 200 OK response code, but when I press the btnFetch button which sends me to a page in which you must but logged in to access, I get the not logged in page. Any ideas?