I have a web service API call that returns BOTH:
- First part is document metadata in the form of JSON (application/JSON)
- 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 here
httpURLConnection.setRequestProperty("Accept", "??? what setting to put to get both JSON and PDF");
enter code here
BufferedReader br = new BufferedReader(new InputStreamReader((httpURLConnection.getInputStream())));
enter code here
StringBuffer sb=new StringBuffer();
enter code here
String line;
enter code here
while ((line = brToGetDocMetadata.readLine()) != null) {
enter code here
sb.append(line);
enter code here
}
enter code here
logger.debug(sb.toString());
Questions:
- What do I need to do to get both metadata (JSON) and PDF in the same call returned to me?
- The StringBuffer gets either JSON, or PDF bytes but I need to get both.
- Should I try Content-Type instead of Accept?