httpurlconnection

HttpURLConnection request being hit twice to the server for downloading file

房东的猫 提交于 2020-01-02 05:12:29
问题 Following is my android code for downloading file from sever. private String executeMultipart_download(String uri, String filepath) throws SocketTimeoutException, IOException { int count; System.setProperty("http.keepAlive", "false"); // uri="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTzoeDGx78aM1InBnPLNb1209jyc2Ck0cRG9x113SalI9FsPiMXyrts4fdU"; URL url = new URL(uri); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.connect(); int lenghtOfFile =

HttpURLConnection request being hit twice to the server for downloading file

拟墨画扇 提交于 2020-01-02 05:12:17
问题 Following is my android code for downloading file from sever. private String executeMultipart_download(String uri, String filepath) throws SocketTimeoutException, IOException { int count; System.setProperty("http.keepAlive", "false"); // uri="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTzoeDGx78aM1InBnPLNb1209jyc2Ck0cRG9x113SalI9FsPiMXyrts4fdU"; URL url = new URL(uri); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.connect(); int lenghtOfFile =

Android KitKat HttpURLConnection disconnect AsyncTask

↘锁芯ラ 提交于 2020-01-01 09:13:10
问题 In my application, I download a file using an HttpURLConnection in an AsyncTask. If the file takes too long to download, then I want cancel it; and I do this by closing the stream and calling disconnect() on the HttpURLConnection object. The code has worked flawlessly for years in Android. However, now that KitKat is out, issues have popped up. Specifically, the disconnect() call itself takes several seconds or more to complete. In pre-KitKat devices, it took a millisecond or less. What is

Persistent HttpURLConnections on Android

烂漫一生 提交于 2020-01-01 03:49:05
问题 I've got an issue trying to get the Android application (well, Service, it case it makes any difference) to use persistent HTTP 1.1 connections. The following loop (simplified test case) works through a single TCP session on a desktop JRE, but on an Android device results in the whole socket creation/teardown cycle. while (true) { URL url; try { url = new URL("http://10.0.0.125:8080/SRV?"); URLConnection connection = url.openConnection(); HttpURLConnection httpConnection = (HttpURLConnection)

URLConnection always returns 400 : Bad Request when I try to upload a .wav file

此生再无相见时 提交于 2019-12-31 05:41:09
问题 I want to implement some code that does exactly what I accomplish when I execute a CURL command in my Mac's terminal, which is to upload a .wav file to a Server. I already accomplished this for one server before, so my general thinking works (and my code too), ....but now I want to accomplish the same but on a different server. This time I am having trouble and all I get are "400:Bad Request" This is he CURL command I want to do on Android, I have added a "-v" so you can see the verbose of my

HttpUrlConnection with post request and parameter as Json object android

不想你离开。 提交于 2019-12-31 02:24:06
问题 Hi I am developing small android application in which I want to use HttpUrlConnection post request with params as json object. But its not working for me I did it in following way: try { URL url; DataOutputStream printout; DataInputStream input; url = new URL ("https://abc.com"); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("POST"); urlConnection.setDoInput (true); urlConnection.setDoOutput (true); urlConnection.setUseCaches (false

HttpURLConnection POST, conn.getOutputStream() throwing Exception

女生的网名这么多〃 提交于 2019-12-31 01:44:08
问题 I want to make a POST by using HttpURLConnection. I am trying this in 2 ways, but I always get an excetion when doing: conn.getOutputStream(); The exception I get in both cases is: java.net.SocketException: Operation timed out: connect:could be due to invalid address function1: public void makePost(String title, String comment, File file) { try { URL servlet = new URL("http://" + "www.server.com/daten/web/test/testupload.nsf/upload?CreateDocument"); HttpURLConnection conn=(HttpURLConnection

How do download a file with login using HttpURLConnection

﹥>﹥吖頭↗ 提交于 2019-12-30 07:44:10
问题 For my Android app I need to download a file from a site requiring login. It is not basic http authentication but rather form emulation. Being new to Android I really don't know how to get started, but in PHP it is easy with cUrl: // Set standard options curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3"); curl_setopt($ch,

Android read text file from internet

断了今生、忘了曾经 提交于 2019-12-30 07:41:39
问题 I want to read a remote text file and show its content in a textview. I have written this below code, but it doesn't get any information from the text file. How can I find the reason of this problem or solve it? isn't there anything wrong in my code? private void readFile() { try { String path ="http://host.com/info.txt"; URL u = new URL(path); HttpURLConnection c = (HttpURLConnection) u.openConnection(); c.setRequestMethod("GET"); c.setDoOutput(true); c.connect(); InputStream in = c

Android HttpUrlConnection getInputStream throws NullPointerException

血红的双手。 提交于 2019-12-30 07:10:12
问题 I am trying to download the image from this url: https://hme_player_pictures.s3.amazonaws.com/test-512813ed3b83286c72f376c7-thumb100.jpg here is stack trace: 03-21 12:58:04.040: W/System.err(7084): java.lang.NullPointerException 03-21 12:58:04.040: W/System.err(7084): at libcore.net.http.HttpConnection$Address.hashCode(HttpConnection.java:343) 03-21 12:58:04.045: W/System.err(7084): at java.util.HashMap.get(HashMap.java:298) 03-21 12:58:04.050: W/System.err(7084): at libcore.net.http