Java client for RESTful service

I'm trying to write a java client to access a restful service without using jersey or other libs. Using HttpURLConnection works great. I can hit the service and get a result back. I can also use the setRequestMethod() to specify whether I'm doing a GET, POST, etc.

What I cannot figure out how to do is specify the return content-type. That is, for a service that can return either application/xml or application/json (or other types), how do I specify which one I want back? I can use addRequestProperty("Content-Type","application/xml") to say what I'm sending in the request, but how to I specify content type for the response?

Who is Participating?
addRequestProperty("Accept" ,"application/xml; application/json") ;
sziloraAuthor Commented:
Super! Thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.