Note that there are some explanatory texts on larger screens.

plurals
  1. POexectuing http POST returns HTML instead of JSON
    text
    copied!<p><strong>EDIT</strong> completely re-working the question for better understanding</p> <p>I have to query the given url <code>http://api.bf3stats.com/pc/player/</code> with 2 POST parameters: 'player' (for player name) and 'opt' (for options). I've tested it on <a href="http://www.requestmaker.com/" rel="noreferrer">http://www.requestmaker.com/</a> with following data: <code>player=Zer0conf&amp;opt=all</code>. 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:</p> <pre><code> 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; } </code></pre> <p>and that's how I make the request:</p> <pre><code> public void postData(String url, String name) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); try { List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(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) { } } </code></pre> <p>What I'm getting in the 'test" String is not JSON, but the complete HTML-markup of some bf3stats page. Any ideas what could be wrong with my request? </p> <p><img src="https://i.stack.imgur.com/zJXnx.jpg" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload