Android download PDF from URL then open it with a PDF reader

Hi the problem is in FileDownloader class urlConnection.setRequestMethod(“GET”); urlConnection.setDoOutput(true); You need to remove the above two lines and everything will work fine. Please mark the question as answered if it is working as expected. Latest solution for the same problem is updated Android PDF Write / Read using Android 9 (API level 28) Attaching the … Read more

HttpURLConnection.getResponseCode() returns -1 on second invocation

Try set this property to see if it helps, http.keepAlive=false I saw similar problems when server response is not understood by UrlConnection and client/server gets out of sync. If this solves your problem, you have to get a HTTP trace to see exactly what’s special about the response. EDIT: This change just confirms my suspicion. … Read more

Pass cookies from HttpURLConnection (java.net.CookieManager) to WebView (android.webkit.CookieManager)

I would like to suggest a completely different approach to your problem. Instead of copying cookies from one place to another (manual sync), let’s make HttpURLConnection and WebViews use the same cookie storage. This completely eliminates the need for sync. Any cookie updated in any one of them, will be immediately and automatically reflected in … Read more

FileNotFoundException while getting the InputStream object from HttpURLConnection

I don’t know about your Spring/JAXB combination, but the average REST webservice won’t return a response body on POST/PUT, just a response status. You’d like to determine it instead of the body. Replace InputStream response = con.getInputStream(); by int status = con.getResponseCode(); All available status codes and their meaning are available in the HTTP spec, … Read more

URLConnection getContentLength() is returning a negative value

By default, this implementation of HttpURLConnection requests that servers use gzip compression. Since getContentLength() returns the number of bytes transmitted, you cannot use that method to predict how many bytes can be read from getInputStream(). Instead, read that stream until it is exhausted: when read() returns -1. Gzip compression can be disabled by setting the … Read more