httpurlconnection

Convert Curl to Java equivalent

北城余情 提交于 2019-12-01 05:39:03
问题 I'm working with New Relic REST API for the first time, I have a curl command: curl -X GET 'https://api.newrelic.com/v2/applications/appid/metrics/data.json' \ -H 'X-Api-Key:myApiKey' -i \ -d 'names[]=EndUser/WebTransaction/WebTransaction/JSP/index.jsp' I want to send this command in a java servlet and get a JSON object from the response ready for parsing, What is the best solution? HttpURLConnection? Apache httpclient? I've tried a few different solutions, but nothing has worked so far and

EPIPE (Broken pipe) while uploading?

时光怂恿深爱的人放手 提交于 2019-12-01 05:06:05
问题 i have a problem in my code but i don't know where is it the E log report 04-08 05:47:46.745: E/Upload Server(20080): Starting : /storage/sdcard1/Music/Piano (my favourites)/11 Tchaikovsky - The Music Lovers.mp3 04-08 05:47:47.136: E/Upload Server(20080): Connection Error : sendto failed: EPIPE (Broken pipe) what is (EPIPE) ? , when i attempt to upload image its upload successfully but any other file E Cat report (Broken pipe) why ! this is my uploading code @Override protected String

Android: Uploading a photo in Cloudinary with progress callback in HttpURLConnection

China☆狼群 提交于 2019-12-01 04:16:20
I'm trying to modify the open source library of cloudinary so that I can listen to the progress of the upload of my photo. The library class contains a MultipartUtility java class that I modified to listen to the progress of the upload. The original code before modifications can be found on github: https://github.com/cloudinary/cloudinary_java/blob/master/cloudinary-android/src/main/java/com/cloudinary/android/MultipartUtility.java I literally modified it to resemble the code from another cloud service CloudFS that supports progress when uploading files / images etc: https://github.com/bitcasa

HttpURLConnection.getResponseCode() throws IOException when code is known

↘锁芯ラ 提交于 2019-12-01 03:05:00
How come HttpURLConnection.getResponseCode() throws IOException even if the status is known? Caused by: java.io.IOException: Server returned HTTP response code: 412 for URL: <my url> It's not a problem of getting the response code because it is written in the exception message. I would expect to have an option to get the status code (even if it's not ~200) without getting an exception, so I'll be able to decide in my code what to do. Full stack trace: Caused by: java.io.IOException: Server returned HTTP response code: 412 for URL: <my url> at sun.net.www.protocol.http.HttpURLConnection

AndroidHttpClient versus HttpUrlConnection for API Level 9 and above

帅比萌擦擦* 提交于 2019-12-01 03:03:33
Which is better for API Level 9(Gingerbread) and why? Is there any benefit to use AndroidHttpClient over HttpUrlConnection? Any help or guidance will be well appreciated. Google doesn't recommend using AndroidHttpClient , only on very old Android versions. But as you can see in many questions on SO, HttpURLConnection is not easy to use. It's very low-level and doesn't have a comfortable interface. You have to know quite a lot how it's working internally and if you have luck, you get exceptions when you use it the wrong way. For that reason many libraries have been developed for Android

How do download a file with login using HttpURLConnection

只愿长相守 提交于 2019-12-01 01:11:29
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, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, "somecookiejar");

Android read text file from internet

老子叫甜甜 提交于 2019-12-01 00:54:18
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.getInputStream(); Log.e("value",in.toString()); AssetManager mngr=getAssets(); ByteArrayOutputStream bo = new

Android: Uploading a photo in Cloudinary with progress callback in HttpURLConnection

醉酒当歌 提交于 2019-12-01 00:26:01
问题 I'm trying to modify the open source library of cloudinary so that I can listen to the progress of the upload of my photo. The library class contains a MultipartUtility java class that I modified to listen to the progress of the upload. The original code before modifications can be found on github: https://github.com/cloudinary/cloudinary_java/blob/master/cloudinary-android/src/main/java/com/cloudinary/android/MultipartUtility.java I literally modified it to resemble the code from another

Android HttpUrlConnection getInputStream throws NullPointerException

北城以北 提交于 2019-11-30 23:58:35
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.HttpConnectionPool.get(HttpConnectionPool.java:67) 03-21 12:58:04.050: W/System.err(7084): at libcore.net.http

httpurlconnection thread safety

烈酒焚心 提交于 2019-11-30 23:17:09
Is HttpUrlConnection thread safe? I.e. if I have an HttpConnection instance connected to a server and this instance is used by different threads (e.g.try to send a POST concurrently) how will this situation be handled by HttpUrlConnection? a) Will they send the POSTs serially, or b) the first thread sends the POST, gets the response and then the second thread will send the POST? If they send the POSTs serially, this means multiple active POSTs to the same tcp connection. Is this allowed? Can it be handled by a server? Thanks It does not say if it is or not in the docs. After looking at the