Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6918011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:48:15+00:00 2026-05-27T09:48:15+00:00

I’m developing an Android app in which I have to do a POST request

  • 0

I’m developing an Android app in which I have to do a POST request to a server, the request in a shell should be like this:

curl -v -H “Accept: application/xml” -H “Content-type: application/json” -X POST -d ‘ {“marca”:{“user_id”:”78″,”lugar_id”:”2″,”tiempo”:”20:20:20″,”distancia_recorrida”:”300″,”velocidad_maxima”:”20.8″, “velocidad_media”:”15.8″, “desnivel”:”100″, “aceleracion”:”5.8″, “fecha”:”2027-11-28 13:32:30″}, “api_token”:””}’ nameOfSerVer

Well, my Java code looks like:

HttpClient httpclient = new DefaultHttpClient();  
                            HttpPost httppost = new HttpPost(NameOfServer); 

try{
String marca ="{\"user_id\":\""+settings.getInt("user_id",0)+"\",\"lugar_id\":\""+id_lugar+"\",\"tiempo\":\""+tiempo+"\"," +
                                "\"distancia_recorrida\":\""+distancia+"\",\"velocidad_maxima\":\""+round((b.getDouble("velMax")*3.6),2, BigDecimal.ROUND_UP)+"\"," +
                                        " \"velocidad_media\":" +
                                "\""+velocidad_media+"\", \"desnivel\":\""+round(b.getDouble("maxDescenso"), 2, BigDecimal.ROUND_UP)+"\"," +
                                        " \"aceleracion\":\""+round(b.getDouble("ac")/9.806, 2, BigDecimal.ROUND_UP)+"\"," +
                                " \"fecha\":\"2014-11-28 13:32:30\"}";



                                JSONObject json = new JSONObject();

                                json.put("marca", marca);
                                json.put("api_token",settings.getString("api_token", ""));
                                StringEntity se = new StringEntity(json.toString());  

                                se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                                httppost.setEntity(se);

                                HttpResponse response = httpclient.execute(httppost);  
                                HttpEntity responseEntity =response.getEntity();

                                Log.e("USER", EntityUtils.toString(responseEntity).trim());
    } catch (UnsupportedEncodingException e) {
                                // TODO Auto-generated catch block
                                Log.e("USER", e.getMessage());
                            } catch (ClientProtocolException e) {
                                // TODO Auto-generated catch block
                                Log.e("USER", e.getMessage());
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                Log.e("USER", e.getMessage());
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }  

It works perfectly from the command shell, but when sending the request from the phone, I get NOT AUTHORIZED

Any help would be much appreciated.

Thank you!

I’ve done what a nice user suggested me and here’s what I got:

POST /marcas HTTP/1.1
Content-Length: 300
Content-Type: text/plain; charset=ISO-8859-1
Content-Type: application/json
Host: >HOSTNAME>
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
Expect: 100-Continue

HTTP/1.1 100 Continue

{"marca":"{\"user_id\":\"78\",\"lugar_id\":\"3\",\"tiempo\":\"00:14\",\"distancia_recorrida\":\"0.0\",\"velocidad_maxima\":\"0.0\", \"velocidad_media\":\"0.0\", \"desnivel\":\"0.0\", \"aceleracion\":\"0.01\", \"fecha\":\"2014-11-28 13:32:30\"}","api_token":"47fc42ea02a20456d7b901d5b26590a84d0a92d2"}HTTP/1.1 401 Authorization Required
Date: Sun, 04 Dec 2011 02:48:37 GMT
Server: Apache/2.2.9 (Debian) Phusion_Passenger/3.0.2 PHP/5.2.6-1+lenny9 with Suhosin-Patch
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.2
X-UA-Compatible: IE=Edge,chrome=1
X-Runtime: 0.004435
Cache-Control: no-cache
Status: 401
Vary: Accept-Encoding
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

e
NOT AUTHORIZED

It’s weird that the “\” appear in the post request, while, attending to the code… they come from a String, that is supposed to ignore them… isn’t it?

Still completely blind in this issue…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:48:16+00:00Added an answer on May 27, 2026 at 9:48 am

    That’s it, the error was in:

    String marca ="{\"user_id\":\""+settings.getInt("user_id",0)
    

    The server only accepted Strings… and it was parsed as an int.

    Thank you everyone! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.