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 ?

Sotirios Delimanolis
  • 252,278
  • 54
  • 635
  • 683

1 Answers1

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.

Community
  • 1
  • 1
Sotirios Delimanolis
  • 252,278
  • 54
  • 635
  • 683