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

  • SEARCH
  • Home
  • 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 7950847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:23:27+00:00 2026-06-04T02:23:27+00:00

I need to send some data from my Android device to my server. I

  • 0

I need to send some data from my Android device to my server. I am doing this through JSON. I have implemented the JSON post on Android, and I am trying to do a mapping on the server side in order to retrieve that data. My problem is that I keep getting an empty string.

Android method used to send JSON:

private void sendJson(final String json, final String URL) {
    Thread t = new Thread(){
    public void run() {
            Looper.prepare(); //For Preparing Message Pool for the child Thread
            HttpClient client = new DefaultHttpClient();
            HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
            try{
                HttpPost post = new HttpPost(URL);
                StringEntity se = new StringEntity(json);  
                se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                post.setEntity(se);
                client.execute(post);
            }
            catch(Exception e){
                e.printStackTrace();
            }
            Looper.loop(); //Loop in the message queue
        }
    };
    t.start();      
}

Server-side method:

@RequestMapping(value = "/getLatestCalls", method = RequestMethod.POST)
public void getData(@ModelAttribute String json){
    //... do something 
}

The thing is that in this method my json String is “” every time. I have also tried using @RequestParam but with that it doesn’t enter the method anymore. I have also tried with @ModelAttribute("json").

Can someone enlighten me a little here? Thank you in advance.

  • 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-06-04T02:23:29+00:00Added an answer on June 4, 2026 at 2:23 am

    Here is the solution and it works fine.

    server-side

    @Controller
        public class DataCollector {
    
            @RequestMapping(value = "/clientdatacollector", method = RequestMethod.POST)
            public @ResponseBody
            void abc(Writer writer, @RequestParam("gpsdata") String gpsJSON) {
    
    
    
                try {
                    // here is your jsonstring ;)
                    writer.write(gpsJSON.toString());
    
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    
            }
    
        }
    

    client-side

     public static void httptest() {
                ArrayList<TravellingData> tdArray = new ArrayList<TravellingData>();
                Gson gson = new Gson();
                String jsonString = "";
                for (int i = 0; i < 1; i++) {
                    tdArray.add(ObjectCreater.createMockTravellingDataObject());
                }
    
                jsonString = gson.toJson(tdArray);
    
                HttpClient client = new DefaultHttpClient();
    
                HttpPost post = null;
                try {
                    post = new HttpPost(
                            "http://localhost:8080/uygulama/clientdatacollector");
                } catch (URISyntaxException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                try {
                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
                    nameValuePairs.add(new BasicNameValuePair("gpsdata", jsonString));
                    post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    
                    HttpResponse response = null;
                    try {
                        response = client.execute(post);
                    } catch (HttpException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    BufferedReader rd = new BufferedReader(new InputStreamReader(
                            response.getEntity().getContent()));
                    String line = "";
                    while ((line = rd.readLine()) != null) {
                        System.out.println(line);
                    }
    
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
            }
    

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

Sidebar

Related Questions

I need to send some byte array from android device to Servlet. For this
I have a requirement where I need to send some data from my server
I need to send some of my data into another server. Actually to post
I need to send some data periodically from an Android app to an external
I need to send some data from a SQL DB Server on an internal
I need to send some post data to another server in mule 3.1.2. Here
I'm trying to to send some post data to a Apache server from iPad
I need to send some data with radio button. This buttons are <td> <span
I need to send data from an IIS web server A to an Apache
I need to send some data to a C program from my app in

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.