EDIT completely re-working the question for better understanding
I have to query the given url http://api.bf3stats.com/pc/player/
with 2 POST parameters: 'player' (for player name) and 'opt' (for options). I've tested it on http://www.requestmaker.com/ with following data: player=Zer0conf&opt=all
. I'm getting a correct JSON response (thought I don't know how their site performs the query, I guess it's php). Now I'm trying to do the same in Android:
private StringBuilder inputStreamToString(InputStream is) {
//this method converts an inputStream to String representation
String line = "";
StringBuilder total = new StringBuilder();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
try {
while ((line = rd.readLine()) != null) {
total.append(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return total;
}
and that's how I make the request:
public void postData(String url, String name) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
//qname is a String containing a correct player name
nameValuePairs.add(new BasicNameValuePair("player", qname));
nameValuePairs.add(new BasicNameValuePair("opt", "all"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
//test is just a string to check the result, which should be in JSON format
test = inputStreamToString(response.getEntity().getContent())
.toString();
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
}
What I'm getting in the 'test" String is not JSON, but the complete HTML-markup of some bf3stats page. What could be wrong with my request?