To test the server I use cURL, using this command:

curl -H "TOKEN_NAME: TOKEN_VALUE" https: //.../assets.json? max_id = -1

where I specify the name of the token and its value to access json. The answer comes right. In Java (Android) I tried it in many ways, as a result it returns only html, with an error. Here is one of the methods used:

private void sendPost3() throws Exception { Log.d("test", "------------------sendPost3------------------------"); HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(); // add header post.setHeader(TOKEN_NAME, TOKEN_VALUE); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair(TOKEN_NAME, TOKEN_VALUE)); post.setEntity(new UrlEncodedFormEntity(urlParameters)); post.setURI(new URI(mUrl)); HttpResponse response = client.execute(post); for(Header h : post.getAllHeaders()) { Log.d("test", "header = " + h.getName() + h.getValue()); } Log.d("test", "\nSending 'POST' request to URL : " + mUrl); Log.d("test", "Post parameters : " + post.getEntity().toString()); Log.d("test", "Response Code : " + response.getStatusLine().getStatusCode()); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line; while ((line = rd.readLine()) != null) { result.append(line); } Log.d("test", result.toString()); } 

What am I doing wrong?

    1 answer 1

    cURL 'you send the GET request, and from the Java code - POST .

    • Really. And I read somewhere that you need post and get and did not even think to use it =) thanks a lot for the answer! Replaced HttpPost with HttpGet and that's it, I don’t understand just what the difference is, the title is passed in both cases, probably in the post it is transmitted in the body, and therefore it was not read. - iamtihonov