httpurlconnection

java.io.IOException : No authentication challenges found

大兔子大兔子 提交于 2019-11-26 20:26:32
I am newbie to android and this is my first project on android. I am struggling with "authentication" problem for more than a day. I tried several options but none of them worked. Basically, I want to call a REST API and get response. I am sure that there is no problem in API as I use the same one in another iOS application. I pass authorization header but still authentication no found message is shown. I found few question on stackoverflow related to this, but some of them did not work and some does not make sense to me. I get status code 401 . I know this means either no authentication

HttpURLConnection worked fine in Android 2.x but NOT in 4.1: No authentication challenges found

£可爱£侵袭症+ 提交于 2019-11-26 19:56:28
I have some typical codes which used HttpURLConnection to get a file with an URL. They worked fine in android 1.x and 2.x. But failed in Android 4.1! I searched on the web but found little similar information. Would anybody please help to investigate this issue? private String mURLStr; private HttpURLConnection mHttpConnection; ... url = new URL(mURLStr); ... mHttpConnection = (HttpURLConnection) url.openConnection(); mHttpConnection.setDoOutput(true); mHttpConnection.setRequestMethod("GET"); ... InputStream is = mHttpConnection.getInputStream(); The getInputStream method throws an exception:

How to check if InputStream is Gzipped?

只谈情不闲聊 提交于 2019-11-26 19:22:21
问题 Is there any way to check if InputStream has been gzipped? Here's the code: public static InputStream decompressStream(InputStream input) { try { GZIPInputStream gs = new GZIPInputStream(input); return gs; } catch (IOException e) { logger.info("Input stream not in the GZIP format, using standard format"); return input; } } I tried this way but it doesn't work as expected - values read from the stream are invalid. EDIT: Added the method I use to compress data: public static byte[] compress

Two way sync for cookies between HttpURLConnection (java.net.CookieManager) and WebView (android.webkit.CookieManager)

╄→尐↘猪︶ㄣ 提交于 2019-11-26 18:59:16
问题 Unfortunately, there's a multitude of cookie managers for Android. The cookies for HttpURLConnection are maintained by java.net.CookieManager and the cookies for WebView are maintained by android.webkit.CookieManager . These cookie repositories are separate and require manual synchronization. My app uses both HttpURLConnections and shows WebViews (it's a native-HTML hybrid). Naturally, I want both to share all cookies - so I will have a transparent session all across. More Specifically: When

Why do you have to call URLConnection#getInputStream to be able to write out to URLConnection#getOutputStream?

六月ゝ 毕业季﹏ 提交于 2019-11-26 18:53:34
I'm trying to write out to URLConnection#getOutputStream , however, no data is actually sent until I call URLConnection#getInputStream . Even if I set URLConnnection#doInput to false, it still will not send. Does anyone know why this is? There's nothing in the API documentation that describes this. Java API Documentation on URLConnection: http://download.oracle.com/javase/6/docs/api/java/net/URLConnection.html Java's Tutorial on Reading from and Writing to a URLConnection: http://download.oracle.com/javase/tutorial/networking/urls/readingWriting.html import java.io.IOException; import java.io

Parse JSON from HttpURLConnection object

别说谁变了你拦得住时间么 提交于 2019-11-26 18:25:59
I am doing basic http auth with the HttpURLConnection object in Java. URL urlUse = new URL(url); HttpURLConnection conn = null; conn = (HttpURLConnection) urlUse.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Content-length", "0"); conn.setUseCaches(false); conn.setAllowUserInteraction(false); conn.setConnectTimeout(timeout); conn.setReadTimeout(timeout); conn.connect(); if(conn.getResponseCode()==201 || conn.getResponseCode()==200) { success = true; } I am expecting a JSON object, or string data in the format of a valid JSON object, or HTML with simple plain text

Can you explain the HttpURLConnection connection process?

房东的猫 提交于 2019-11-26 18:03:06
I am using HTTPURLConnection to connect to a web service. I know how to use HTTPURLConnection but I want to understand how it works. Basically, I want to know the following: On which point does HTTPURLConnection try to establish a connection to the given URL? On which point can I know that I was able to successfully establish a connection? Are establishing a connection and sending the actual request done in one step/method call? What method is it? Can you explain the function of getOutputStream and getInputStream in layman's term? I notice that when the server I'm trying to connect to is down,

FileNotFoundException for HttpURLConnection in Ice Cream Sandwich

徘徊边缘 提交于 2019-11-26 17:40:17
问题 I have an Android app that works fine with Android 2.x and 3.x, but it fails when run on Android 4.x. The problem is in this section of code: URL url = new URL("http://blahblah.blah/somedata.xml"); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.connect(); InputStream inputStream = urlConnection.getInputStream(); When the application is running on Android 4.x, the getInputStream()

How do I persist cookies when using HTTPUrlConnection?

跟風遠走 提交于 2019-11-26 17:36:27
问题 I've begun using the recommended HTTPUrlConnection and moved away from the DefaultHTTPClient . One of the things that I haven't been able to glue back together is the use of a persistent cookie store. I'd like to simply attach a custom cookie handler/manager to my connection to store the cookies. The Android documentation hasn't been very helpful as it wraps up the subject about cookies in two lines. I've been using LoopJ's PersistentCookieStore earlier and that worked beautifully. Any idea

Getting java.net.SocketTimeoutException: Connection timed out in android

情到浓时终转凉″ 提交于 2019-11-26 17:23:28
I'm relatively new to android development. I'm developing an android application where i'm sending request to web server and parsing json objects. Frequently i'm getting java.net.SocketTimeoutException: Connection timed out exception while communicating with the server. Some times it will work perfectly without any problem. I know this same question has been asked in SO many times. But still i didn't get any satisfying solution to this problem. I'm posting my logcat and app-server communication code below. public JSONObject RequestWithHttpUrlConn(String _url, String param){ HttpURLConnection