[Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

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?

1 Solution
addRequestProperty("Accept" ,"application/xml; application/json") ;
sziloraAuthor Commented:
Super! Thanks.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now