I use the AsyncHttpClient library from http://loopj.com/android-async-http/ and force it to access web services correctly to receive JSON responses. Now I am trying to call a web service that transfers files back to the client via HTTP. Therefore, I use BinaryHttpResponseHandler to capture the returned byte [] data. However, every time I try to call a method, it fails, and when examining the Throwable object, the exception is "org.apache.http.client.HttpResponseException: Content-Type is not allowed!".
I tried to specify a list of content types allowed according to the documents, but this did not change the situation. I am mainly streaming PDF files, but ideally I do not want to specify a list of content types, I want to be able to download any type of file. The code I use is as follows:
AsyncHttpClient httpClient = new AsyncHttpClient(); String[] allowedContentTypes = new String[] { "application/pdf", "image/png", "image/jpeg" }; httpClient.get(myWebServiceURL, new BinaryHttpResponseHandler(allowedContentTypes) { @Override public void onSuccess(byte[] binaryData) {
I also tried not to specify any types of content, just using:
new BinaryHttpResponseHandler()
but it didn’t matter.
source share