I am attempting to help a student write an android app that will contact a specific webserver. From the looks of the website, you can issue a GET requestion with your web browser and you get back a cookie session and an "authenticity token" (see the source of the page as an invisible input)
We issue a GET request and then want to follow it up with the post, but we are receiving a status code of 404 on the post. On a side note, the first GET request returns a code of 200.
Does anyone have any ideas? Below is the code that gets executed...
public void run()
{
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("https://co22.herokuapp.com/login/");
HttpPost httpPost = new HttpPost("https://co22.herokuapp.com/login/sessions");
HttpResponse response;
try
{
response = httpClient.execute(httpGet);
Log.d("matt",response.getStatusLine().toString());
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("session[network_id]", username));
nameValuePairs.add(new BasicNameValuePair("session[password]", password));
nameValuePairs.add(new BasicNameValuePair("authenticity_token","9yvxPOUpRFdsTeHAZtISEfBHpElDTHzvMjAbQnxOHDM="));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpClient.execute(httpPost);
Log.d("matt",response.getStatusLine().toString());
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}