httpurlconnection

HttpURLConnnection request failures on Android 6.0 (MarshMallow)

自作多情 提交于 2019-12-08 05:31:56
问题 I am using Google's Volley library for my application project , that targets minimum api level 14.So, Volley library uses HttpURLConnection as the NetworkClient. Therefore , there should not be any issue related to Removal of Apache HTTPClient. However, I have done the configuration required for 6.0 Sdk i.e compileSdkVersion 23, build-tool-version 23.0.1 and build:gradle:1.3.1' and even tried adding useLibrary 'org.apache.http.legacy'. Have updated the same for Volley library project in my

Android HttpURLConnection VERY slow

喜欢而已 提交于 2019-12-08 05:08:31
问题 This is the situation I'm facing with the code below: As you can see I'm trying to read an HTTP stream. When I run the following code on the Android simulator it works 100% of the time, when I run the following code on my Galaxy S3 while on 3G it works 100% of the time, when I try to connect to the URL using my laptop browser it works 100% of the time, when I try to connect using the Galaxy S3 browser (in both wifi and 3g) it works... 100% of the time. HOWEVER, when I try to connect using my

HttpURLConnection getInputStream() has one second delay

只谈情不闲聊 提交于 2019-12-08 03:10:24
问题 I am using HttpURLConnection for making POST requests. I observe always the same behaviour during tests: first request runs very fast (miliseconds) all following requests take one second + some miliseconds So something is causing 1 second delay. What can it be? The delay is happening exactly in HttpURLConnection#getInputStream(). I replaced the implementation with HttpClient - then everything is OK, no second delays (so it is not the server fault). But I really don't want to use any external

How to prevent CONNECT method call from HttpsURLConnection

故事扮演 提交于 2019-12-08 01:54:33
问题 I have an Android client making HTTPS request to a server. The firewall logs have entries for CONNECT request methods which are not desired. When would the CONNECT request get sent out and how can I prevent it from being sent? I expect only a GET request. My understanding is that the call to openConnection() does not actually make a request and that the GET request would go on the call to getResponseMessage(). How can I disable the http client from attempting to establish a proxy tunnel? Here

How to reset URLConnection in java?

时间秒杀一切 提交于 2019-12-08 01:32:36
问题 is there any way to reset the connection,so that i can read from starting of the document? It is a slow process that reconnecting to read from sarting,i want to read a file 20 times per second through http,is there any other way to do this? 回答1: URLConnection is an easy but somewhat "dumb" class. I can suggest you to do it the Java way: instantiate a new URLConnection. ;) Java is not really a language that encorages reusage of objects. You can try resetting the input stream, see the docs for

“java.lang.IllegalStateException: Cannot set request property after connection is made” error in Android

陌路散爱 提交于 2019-12-08 00:44:14
问题 I am new to Android and trying to get HTML content of a web page and that is when I came across this issue. java.lang.IllegalStateException: Cannot set request property after connection is made Code : public static String getHTMLPage(String inputURL, String host, String referer, String cookie, String breakString) { String htmlContent = ""; try { URL u = new URL(inputURL); HttpURLConnection uc = (HttpURLConnection) u.openConnection(); uc.setRequestProperty("Host", host); uc.setRequestProperty(

Sending binary data with HttpURLConnection

[亡魂溺海] 提交于 2019-12-07 22:57:05
问题 i want to use google speech api, i've found this https://github.com/gillesdemey/google-speech-v2/ where everything is explained well, but and im trying to rewrite it into java. File filetosend = new File(path); byte[] bytearray = Files.readAllBytes(filetosend); URL url = new URL("https://www.google.com/speech-api/v2/recognize?output="+outputtype+"&lang="+lang+"&key="+key); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //method conn.setRequestMethod("POST"); //header conn

Setting “User-Agent” parameters for URLConnection for querying Google from a Java application

帅比萌擦擦* 提交于 2019-12-07 17:49:01
问题 I am trying to get the results back from a Google query, in Java as follows: String urlquery = "https://www.google.com/search?hl=en&gl=us&tbm=nws&q=apples&oq=apples"; URL url = new URL(urlquery); URLConnection connection = url.openConnection(); URLConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.0 Safari/532.5"); But, I don't know how to set the "User-Agent" parameters above. From where

Switching from WiFi connection to 3g causes connection to hang?

落花浮王杯 提交于 2019-12-07 17:32:15
问题 I have an application which connects to a web service. I can connect to the web service any number of times without any problem using WIFI or 3G provided that I stay loyal to my connection type during the life cycle of my application. That is if I don't switch from WIFI to 3G. If I switches from WIFI to 3G, I can't get a response anymore. My connection just keeps on waiting for response. I tried 4 scenarios below. I'm only having problem with the 3rd scenario. What could be the problem? 1st

Java - Upload OutputStream as HTTP File Upload

淺唱寂寞╮ 提交于 2019-12-07 14:28:21
问题 I've got a legacy application that writes to an OutputStream , and I'd like to have the contents of this stream uploaded as a file to a Servlet. I've tested the Servlet, which uses commons-fileupload , using JMeter and it works just fine. I would use Apache HttpClient, but it requires a File rather than just an output stream. I can't write a file locally; if there was some in-memory implementation of File perhaps that might work? I've tried using HttpURLConnection (below) but the server