Java client for RESTful service

Posted on 2011-05-03
Last Modified: 2012-05-11
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?

Question by:szilora
    LVL 92

    Accepted Solution

    addRequestProperty("Accept" ,"application/xml; application/json") ;

    Author Closing Comment

    Super! Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Introduction A frequent question goes something like this, "How can I show an introductory page to my clients on the first site visit, but not show it again on every visit?"  The answer is by using a cookie.  This article shows the design pattern f…
    A few customers have recently asked my thoughts on Password Managers.  As Security is a big part of our industry I was initially very hesitant and sceptical about giving a program all of my secret passwords.  But as I was getting asked about them mo…
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now