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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:53:45+00:00 2026-06-05T13:53:45+00:00

I am calling a restful service that returns JSON using the Apache HttpClient. The

  • 0

I am calling a restful service that returns JSON using the Apache HttpClient.

The problem is I am getting different results in the encoding of the response when I run the code on different platforms.

Here is my code:

GetMethod get = new GetMethod("http://urltomyrestservice");
get.addRequestHeader("Content-Type", "text/html; charset=UTF-8");
...
HttpResponse response = httpexecutor.execute(request, conn, context);
response.setParams(params);
httpexecutor.postProcess(response, httpproc, context);
StringWriter writer = new StringWriter();
IOUtils.copy(response.getEntity().getContent(), writer);

When I run this on OSX, asian characters etc return fine e.g. 張惠妹 in the response. But when I run this on a linux server the same code displays the characters as ???

The linux server is an Amazon EC2 instance running Java 1.6.0_26-b03
My local OSX is running 1.6.0_29-b11

Any ideas really appreciated!!!!!

  • 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-05T13:53:47+00:00Added an answer on June 5, 2026 at 1:53 pm

    If you look at the javadoc of org.apache.commons.io.IOUtils.copy(InputStream, Writer):

    Copy bytes from an InputStream to chars on a Writer using the default
    character encoding of the platform.

    So that will give different answers depending on the client (which is what you’re seeing)

    Also, Content-Type is usually a response header (unless you’re using POST or PUT). The server is likely to ignore it (though you might have more luck with the Accept-Charset request header).

    You need to parse the content type’s charset-encoding parameter of the response header, and use that to convert the response into a String (if it’s a String you’re actually after). I expect Commons HTTP has code that will do that automatically for you. If it doesn’t, Spring’s RESTTemplate definitely does.

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

Sidebar

Related Questions

I have a RESTful API serving JSON. I'm calling it like this: - (void)viewDidLoad
While calling from my Web Application, WCF response i am getting is : <s:Envelope
I'm developing a RESTful API for a client. The problem is, he's using a
I'm trying to call a RESTful web service from an Android application using the
I have a RESTful WCF application that makes use of custom classes as service
I'm writing a RESTful webservice that returns custom/existing HTTP headers on successful/unsuccessful operations. For
I am having a heck of a time calling a RESTful service from within
I am calling a restful service via the WebClient method to return some XML.
Can ASIHttpRequest call Restful web service ? I knew that Restkit is good at
When I call the restful service with the following code, I am getting the

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.