0

I have a web service API call that returns BOTH:

  1. First part is document metadata in the form of JSON (application/JSON)
  2. and in the same response returns PDF bytes (application/pdf)

If HttpURLConnection.setRequestProperty("Accept", "application/JSON) is set only the first part is returned with is the metadata in the form of JSON.

If HttpURLConnection.setRequestProperty("Accept", "application/pdf) is set then only the later part of the response is returned in the form of PDF, starting with %PDF and ending with EOF.

The response indeed contains the metadata (first part) and PDF (later part). I can get one part, or the other by the setting above.

[b]But in the single/same call, I need to get both metadata (JSON) and PDF, and I am not able to do so[/b]

I tried with the following and it does not return any result (the result is empty). HttpURLConnection.setRequestProperty("Accept", "application/JSON;application/pdf") - this did not work.

The following configurations also returned empty results: HttpURLConnection.setRequestProperty("Accept", "application/") HttpURLConnection.setRequestProperty("Accept", "/*")

Instead of Accept, I also tried using "Content-Type, with the settings below, and the settings below return no (empty) value. HttpURLConnection.setRequestProperty("Content-Type", "application/") HttpURLConnection.setRequestProperty("Content-Type", "/*")

The code is similar to:

enter code herehttpURLConnection.setRequestProperty("Accept", "??? what setting to put to get both JSON and PDF"); enter code hereBufferedReader br = new BufferedReader(new InputStreamReader((httpURLConnection.getInputStream())));
enter code hereStringBuffer sb=new StringBuffer();
enter code hereString line; enter code herewhile ((line = brToGetDocMetadata.readLine()) != null) { enter code here sb.append(line); enter code here} enter code herelogger.debug(sb.toString());

Questions:

  1. What do I need to do to get both metadata (JSON) and PDF in the same call returned to me?
  2. The StringBuffer gets either JSON, or PDF bytes but I need to get both.
  3. Should I try Content-Type instead of Accept?
Sam G
  • 1
  • 1

0 Answers0