Oliver Goossens
Oliver Goossens

Reputation: 1913

HTTP POST and RESPONSE specific case study

  1. Site: http://na.leagueoflegends.com/ladders/solo-5x5
  2. Search for a a player (example: Jaiybe)
  3. You get redirected (in this case to: http://na.leagueoflegends.com/ladders/solo-5x5?highlight=28&page=1)
  4. Read the content

And I want to do that in java/android.

  1. I analyze the sites POST request when searching, result:

    • op:Search
    • player:Jaiybe
    • ladder_id:3
    • form_build_id:form-fff5e6e2569f1e15e5a5caf2a61c15e2
    • form_id:ladders_filter_form
  2. Build a simple HTTP POST mixture and lets read the content...

The CODE:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://na.leagueoflegends.com/ladders/solo-5x5");

// Add your POST METHOD attributes
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("op", "Search"));
nameValuePairs.add(new BasicNameValuePair("player", Jaiybe));
nameValuePairs.add(new BasicNameValuePair("ladder_id", "3"));
nameValuePairs.add(new BasicNameValuePair("form_build_id","form-daca6fff89cedc352ccc3f533afa3804"));
nameValuePairs.add(new BasicNameValuePair("form_id","ladders_filter_form"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
responseBody = EntityUtils.toString(response.getEntity());
return responseBody;

And when I run it - I get so some kind of a offline page...

The number form_build_id - is constantly changing, but this was no problem, to use still the same one, and also If I would like to "test" if this could be the problem, I have no Idea how would I...

OR: Is there any other - FAST - way how to get same results?

What is strange is that the "error" site source code that I get on android is different as if I run the same on my PC (Win7, Eclipse, Java) or in my browser. As if there would be two versions of offline sites - for mobile and for PC - but my question: HOW WOULD the server know that the code runs on a Android device? Is there a way how to set this up in HttpClient?

Upvotes: 0

Views: 1062

Answers (1)

Che Jami
Che Jami

Reputation: 5151

form_build_id:form-fff5e6e2569f1e15e5a5caf2a61c15e2

This is an auto generated token that is valid for a certain time period. This is probably the source of your problem and the reason the token exists in the first place (to prevent post spams).

As this token does not seem session based, you could actually use an HTTP Get on the page that generates the form and parse out the generated token each time for your HTTP Post.

About OS detection, browsers usually provide information about the OS using the HTTP User-Agent header.

Upvotes: 1

Related Questions