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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:06:37+00:00 2026-06-17T11:06:37+00:00

I have a problem with send ü using json to server. I think that

  • 0

I have a problem with send ü using json to server. I think that I implement everything good ad something wrong is on server. This is code:

public void sendMail(List<String> addresses, String title, String contents, boolean addVcard){
        JSONObject args = new JSONObject();
        HashMap<Long, ArrayList<Long>> pdfs = new HashMap<Long, ArrayList<Long>>();
        if(list == null)
            list = (EmailListFragment)getSupportFragmentManager().findFragmentById(R.id.list_fragment);
        if(list == null)
            list = (EmailListFragment)getSupportFragmentManager().findFragmentByTag(LIST_FRAGMENT);
        if(list != null){
            for(TreeFile pdf: list.getPDFs()){

                if(pdf.type == FilesLoader.PAGE){
                    ArrayList<Long> pages = pdfs.get(pdf.parent);
                    if(pages == null){
                        pages = new ArrayList<Long>();
                        pdfs.put(pdf.parent, pages);
                    }
                    pages.add(pdf.id);
                }else if(pdf.type == FilesLoader.PDF){
                    if(pdfs.get(pdf.id) == null)
                        pdfs.put(pdf.id, new ArrayList<Long>());
                }
            }
        }
        try {
            args.put("emails", new JSONArray(addresses));
            Iterator<Entry<Long, ArrayList<Long>>> it = pdfs.entrySet().iterator();
            JSONObject pdfsArgs = new JSONObject();
                // attachment added by user

            while (it.hasNext()) {
                Entry<Long, ArrayList<Long>> pairs = it.next();
                JSONArray pages = new JSONArray();

                // sorting pages by id
                ArrayList<Long> pageList = (ArrayList<Long>)pairs.getValue();
                Collections.sort(pageList);

                for(Long id: pageList){
                    pages.put(id+"");
                }
                if(pages.length() > 0)
                    pdfsArgs.put(pairs.getKey() + "", pages);
                it.remove(); // avoids a ConcurrentModificationException
            }
            args.put("magazines", pdfsArgs);
//          String mes = null;
//          try {
//              mes = URLEncoder.encode(contents, "CP1252");
//          } catch (UnsupportedEncodingException e) {
//              // TODO Auto-generated catch block
//              e.printStackTrace();
//          }
            args.put("message", contents);
            args.put("subject", title);
            if(getvca.emailPref != null && getvca.emailPref.length() > 0
                    && getvca.emailPref.matches("[a-zA-Z0-9._@+,; \\-]+"))
                args.put("sender", getvca.emailPref);
            else
                args.put("sender", GlobalConfig.getUser());

            if(addVcard){
                args.put("vcard", "1");
                getvca.addTo(args);
            }else{
                args.put("vcard", "0");
            }



        } catch (JSONException e) {
            MY_DEBUG.print(e);
        }

        postData = new SendPostData();
        postData.execute(args);
    }



    private class SendPostData extends AsyncTask<JSONObject, String, Long> {
        ByteArrayOutputStream out;
         @Override
        protected Long doInBackground(JSONObject... objects) {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(GlobalConfig.getSendEmail());

            httppost.addHeader("Authorization", "Basic " + Base64.encodeToString(
                    (GlobalConfig.getAuthString()).getBytes(),Base64.NO_WRAP));
            httppost.addHeader("Accept-Encoding", "CP1252");
            httppost.addHeader("Accept-Encoding", "UTF-8");
            try {
                MY_DEBUG.print(objects[0].toString(4));
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("data", objects[0].toString()));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                // Execute HTTP Post Request
                HttpResponse response = httpclient.execute(httppost);
                out = new ByteArrayOutputStream();
                response.getEntity().writeTo(out);
                out.close();

                publishProgress(out.toString());
                setOut(out);
                MY_DEBUG.LOG(getClass(), "Email server response: " + out.toString());
                if(out != null && out.toString().contains("0"))
                    return (long) 0;
                else
                    return (long) 1;
            } catch (ClientProtocolException e) {
                MY_DEBUG.print(e);
            } catch (IOException e) {
                MY_DEBUG.print(e);
            } catch (JSONException e) {
                MY_DEBUG.print(e);
            }

            Long startPosition = (long) 1;
            return startPosition;
         }
        public void setOut(ByteArrayOutputStream out) {
            this.out = out;
        }

        @Override
        protected void onProgressUpdate(String... progress) {
//             if(progress[0].contains("0")){
         }

In logs I see:

01-16 13:12:42.167: E/ASDASD(27672): {
01-16 13:12:42.167: E/ASDASD(27672):     "position": "",
01-16 13:12:42.167: E/ASDASD(27672):     "phone": "",
01-16 13:12:42.167: E/ASDASD(27672):     "fax": "",
01-16 13:12:42.167: E/ASDASD(27672):     "subject": "",
01-16 13:12:42.167: E/ASDASD(27672):     "surname": "",
01-16 13:12:42.167: E/ASDASD(27672):     "firstname": "",
01-16 13:12:42.167: E/ASDASD(27672):     "emails": [
01-16 13:12:42.167: E/ASDASD(27672):         "test@test.pl"
01-16 13:12:42.167: E/ASDASD(27672):     ],
01-16 13:12:42.167: E/ASDASD(27672):     "vcard": "1",
01-16 13:12:42.167: E/ASDASD(27672):     "sender": "ediusz@gmail.com",
01-16 13:12:42.167: E/ASDASD(27672):     "message": "ü",
01-16 13:12:42.167: E/ASDASD(27672):     "email": "ediusz@gmail.com",
01-16 13:12:42.167: E/ASDASD(27672):     "company": "",
01-16 13:12:42.167: E/ASDASD(27672):     "magazines": {
01-16 13:12:42.167: E/ASDASD(27672):         "90": [
01-16 13:12:42.167: E/ASDASD(27672):             "1",
01-16 13:12:42.167: E/ASDASD(27672):             "2",
01-16 13:12:42.167: E/ASDASD(27672):             "3"
01-16 13:12:42.167: E/ASDASD(27672):         ]
01-16 13:12:42.167: E/ASDASD(27672):     },
01-16 13:12:42.167: E/ASDASD(27672):     "internet": "",
01-16 13:12:42.167: E/ASDASD(27672):     "mobile": ""
01-16 13:12:42.167: E/ASDASD(27672): }

so I think that everything is ok, but server return me error. I don’t have access to server. What do you think about that?

  • 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-17T11:06:39+00:00Added an answer on June 17, 2026 at 11:06 am

    You need to find out what encoding the server uses (probably/hopefully UTF-8) and convert your contents from your used encoding to the correct (server) encoding:

    contents = new String(contents.getBytes("ISO-8859-1"), "UTF-8");
    

    Note: you’d need to do so for all of your data.

    If you use the wrong encoding, it might (indeed) result in an error from the server.

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

Sidebar

Related Questions

I have a web application that receives json from a server. I was using
i have function to send mail with attachment to microsoft exchange server. My problem
I have a problem in posting the data to server by using httpput methods
I have a route in my application that is like this: /deployments/:id/logs.json It is
i'm having a problem when i send data to client using TCP server in
I have problem with Oracle 9.2 and JMS. I created PL/SQL routine to send
I'm a beginner concerning socket programming and I have a problem when I send
I have a problem when trying to send a POST request. The sending method
I have a problem. My webserver sinds 403 responses when I send a DELETE
I try to send an email, but I have a problem, however, I found

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.