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 7820721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:24:21+00:00 2026-06-02T07:24:21+00:00

I am building a small app for my Android phone to forward text messages

  • 0

I am building a small app for my Android phone to forward text messages to a webserver using a very basic REST interface.

I am using the android 4.0.3 SDK. I developed the webservice in python using the Django and the Django restframework package. The setup is completely out of the box. There is basically one endpoint that receives a POST of a JSON object holding the message info (sender, body, date). I have tested the service using cURL with the following command:

curl -X POST -H 'Content-Type: application/json' --data '{"sender":"+xxxxxxxx", "body": "test", "send_date":"2011-03-20 16:32:02"}' http://[...]/messages.json

This all works fine and I get the expected response:

{"body": "test", "send_date": "2011-03-20T16:32:02", "id": 25, "sender": "+xxxxxxxxxx"}

Now I set up the android app. It is a simple BroadcastReceiver child class that includes a private AsyncTask class:

private class httpPost extends AsyncTask<String, Void, JSONObject> {
    protected JSONObject doInBackground(String... args) {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpParams myParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(myParams, 10000);
        HttpConnectionParams.setSoTimeout(myParams, 10000);

        String url = args[0];
        String json=args[1];            
        JSONObject JSONResponse = null;
        InputStream contentStream = null;
        String resultString = "";

        try {
            HttpPost httppost = new HttpPost(url);
            httppost.setHeader("Content-Type", "application/json");
            httppost.setHeader("Accept", "application/json");

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

            for (int i=0;i<httppost.getAllHeaders().length;i++) {
                Log.v("set header", httppost.getAllHeaders()[i].getValue());
            }

            HttpResponse response = httpclient.execute(httppost);

            // Do some checks to make sure that the request was processed properly
            Header[] headers = response.getAllHeaders();
            HttpEntity entity = response.getEntity();
            contentStream = entity.getContent();

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        //convert response to string
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(contentStream,"iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            contentStream.close();
            resultString = sb.toString();
        }catch(Exception e){
            e.printStackTrace();
        }

        Log.v("log", resultString);
        return new JSONObject();
    }


}

As you can see I am just starting to get familiar with Java and the android SDK so please bear with me. This setup actually worked fine in another app that I build to send JSON strings to a Neo4J webservice.

The problem is that when I post the message via Android to my webservice, at some point the content-type gets changed from ‘application/json’ to ‘application/json, application/json’. The log entry in the headers loop still outputs the correct values for each header, however, the webservice returns this error message:

{"error": "Unsupported media type in request 'application/json, application/json'."}

I am puzzled, any help is welcome.

  • 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-02T07:24:23+00:00Added an answer on June 2, 2026 at 7:24 am

    Change this:

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

    To this only:

    httppost.setEntity(new StringEntity(json.toString(), HTTP.UTF_8));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively small app that Im building using vb.net 2.0, and nant.
I'm building an Android app that resizes based on the screen size using different
Total newbie here, please bear with me. Building a very small personal app that
I'm building a small app with ASP.NET MVC and I'm using the ASP.NET membership
I am building a small app using PhoneGap HTML/CSS. Now my problem is that
I am building a small app using wxPython.I have created a menu bar ,
I am building a small app that uses backbone.js on the client side, node.js/socket.io
I am building a small rails app and I need a way to generate
I am building a small facebook app. Trying to search for values in an
I'm currently building a semi-small ruby app for a project. The problem I'm currently

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.