1

I am trying to download data from an URL to a file in xml form, but I am getting it in json instead. My code:

URL url1 = new URL("http://api.eancdn.com/ean-services/rs/hotel/v3/list?cid=55505&minorRev=28"
                            +"&apiKey=m9sur8fsbdemjck7y9yydmfx&locale=en_EN&currencyCode=USD&latitude=" +latitudes[i1]+"&longitude=" + longitudes[i1]);
ReadableByteChannel rbc = Channels.newChannel(url1.getInputStream());
FileOutputStream fos = new FileOutputStream(hotel);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 

How can I get it in xml format ?

2
  • 1
    What does your API require in order to respond with XML? That's not something we can know. Commented Nov 2, 2014 at 18:24
  • So? Just parse it as JSON then. Commented Nov 2, 2014 at 18:24

1 Answer 1

0

The answer completely depends on your API. Is it even possible for it to respond with XML?

Typically, you'll want to provide an Accept header with the appropriate content type. In this case, that is application/xml. This header will indicate to the server that the client only wants response bodies of that content type.

Setting a request header depends on the HTTP client. Here you are just using the URL type. Get an HttpURLConnection from it and set its request property with setRequestProperty.

Sign up to request clarification or add additional context in comments.

2 Comments

what should i put as key and value on the setRequestProperty ?
@alex The accept header name and value. Again, maybe your service does things diiferently.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.