I’m writing an Android app which does exactly the same as our iPad app for our company. But I have 1 issue while developing on the android. The app downloads a file from a webserver. It will call an URL like:
https://www.somedomain.com/API/Download.aspx?param1=test¶m2=test2 etc…
On the iPad this is working perfectly (I use the ASIHTTPRequest class for this). But on Android it is giving me only problems.
As soon as I want to download the file with the android, it downloads a file with a 500 internal server error HTML document instead of the PDF file.
I’ve checked the URL’s, they look exactly the same as on the iPad.
The only thing I can imagine, is that the file which the user downloads is created “on the fly”. So it takes some time (10 or 20 sec) to generate the file, and then the file is being downloaded.
On android I do this:
I have a class which extends:
extends AsyncTask<String, Integer, JSONObject>
In a method, I do this:
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response = httpclient.execute(httpget);
InputStream data = response.getEntity().getContent();
File file = new File(context.getDir("docs", Context.MODE_PRIVATE), FileName);
OutputStream output = new FileOutputStream(file);
ByteStreams.copy(data, output);
Closeables.closeQuietly(output);
But this is giving me a 500 internal server error doc instead of the desired PDF file. What am I missing here? (Sorry, I just started developing for Android so I’m not an expert in this case ;-))
Thanks in advance!
Ok it works now… Stupid thing… I constantly created a new HttpClient so the session was not stored among connections. That is why the server returned a 500 internal server error because the user was not known by the server…
Thanks everyone for your help though!