how do I solve accentuation errors when sending an Android message to an API in php

0

Folks, I'm having trouble sending strings with accents and strings with 2 lines or more. When I send without an accent or with only one line, it usually accepts, however, when I send with an accent, it gives the error.

I've already used an API (Rest Easy) tester, and when I send it there, it usually accepts and does not show any errors, but when I send it through Android, the error ...

This is the snippet of the shipment-related code.

public void enviaDados() {
    new LongOperation().execute("");
}

private class LongOperation extends AsyncTask<String, Void, String> {

    String msg = mensagem.getText().toString();
    String mail = email.toString();

    ProgressBar carrega = (ProgressBar) findViewById(R.id.carregaMsg);

    @Override
    protected String doInBackground(String... params) {
        try {
            Log.v("GG", "Sending sever 1 - try");
            // start - line is for sever connection/communication
            HttpClient httpclient = new DefaultHttpClient();

            HttpPost httppost = new HttpPost("http://www.meuSite.com.br/mural/listener.php");

            String json = "{\"usuario\":[{\"enviado\":\"" + "1" + "\",\"email\":\"" + mail.toString() + "\",\"msg\":\"" + msg.toString() + "\",\"a\":\"" + "2" + "\"}]}"; //msg.toString()

            StringEntity entity1 = new StringEntity(json);
            httppost.setEntity(entity1);
            //informa o tipo de arquivo. . .
            httppost.setHeader("Accept", "application/json");
            httppost.setHeader("Content-type", "application/json");

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

            // end - line is for sever connection/communication
            InputStream is = entity.getContent();
            //_______________________________________________________________________
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }

            result = sb.toString();
            is.close();
            jsonObject = new JSONObject(result);
            //__________________________________________________________________________

        } catch (Exception e) {
            Log.e("log_tag", "Error in http connection "
                    + e.toString());

        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        carrega.setVisibility(View.INVISIBLE);
        try {
            alerta();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        mensagem.setText("");
    }

    @Override
    protected void onPreExecute() {
        carrega.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onProgressUpdate(Void... values) {
    }
}

If anyone knows how to help me, I would be very grateful. Any tips are welcome, thank you for the attention!

Hug!

    
asked by anonymous 27.11.2015 / 20:37

0 answers