urlconnection

Java Webstart and URLConnection caching API

耗尽温柔 提交于 2019-12-03 09:30:58
The description of the URLConnection caching API states as the last sentence: There is no default implementation of URLConnection caching in the Java 2 Standard Edition. However, Java Plugin and Java WebStart do provide one out of the box. Where can I find more information about the Webstart ResponseCache? Which Versions of Webstart on which platforms activate Caching? In which cases is it active? Only HTTP Get? Can it be configured? Is the sourcecode available? Background: Case 1 With following (groovy) code def url = new URL('http://repo1.maven.org/maven2/') def connection = url

Is it possible to check progress of URLconnection.getInputStream()?

别来无恙 提交于 2019-12-03 07:46:06
I want to check progress of downloading file by URLconnection. Is it possible or should I use another library? This is my urlconnection function: public static String sendPostRequest(String httpURL, String data) throws UnsupportedEncodingException, MalformedURLException, IOException { URL url = new URL(httpURL); URLConnection conn = url.openConnection(); //conn.addRequestProperty("Content-Type", "text/html; charset=iso-8859-2"); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); BufferedReader rd = new BufferedReader(new

Setting custom header using HttpURLConnection

别等时光非礼了梦想. 提交于 2019-12-03 07:04:59
I am simply making a GET request to a Rest API using HttpURLConnection . I need to add some custom headers but I am getting null while trying to retrieve their values. Code: URL url; try { url = new URL("http://www.example.com/rest/"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // Set Headers conn.setRequestProperty("CustomHeader", "someValue"); conn.setRequestProperty("accept", "application/json"); // Output is null here <-------- System.out.println(conn.getHeaderField("CustomHeader")); // Request not successful if (conn.getResponseCode() != HttpURLConnection.HTTP_OK)

How does URLConnection.setUseCaches() work in practice?

放肆的年华 提交于 2019-12-03 00:16:50
I have an Applet which is loading images over a http connection using URLConnection. I am setting setUseCaches(true) for all connections, but still not seeing any caching behavior. My image's HTTP headers have reasonable cache settings. If you look at bug 4528599 there is this rather mysterious statement: The current version (1.3.1) of Java Plug-In only checks the browser cache for files whose names end in .jar or .class. I have been told that for Java Plug-In 1.4 the browser cache will be checked for the following file types: .class, .jar, .zip, .jpg, .gif, .wav, .au. Of course, this was

URLConnection is not allowing me to access data on Http errors (404,500,etc)

孤街醉人 提交于 2019-12-02 20:26:15
I am making a crawler, and need to get the data from the stream regardless if it is a 200 or not. CURL is doing it, as well as any standard browser. The following will not actually get the content of the request, even though there is some, an exception is thrown with the http error status code. I want the output regardless, is there a way? I prefer to use this library as it will actually do persistent connections, which is perfect for the type of crawling I am doing. package test; import java.net.*; import java.io.*; public class Test { public static void main(String[] args) { try { URL url =

SSLProtocolException when reading https responses on Android 2.3.3 devices

拥有回忆 提交于 2019-12-02 19:45:50
问题 I'm facing a problem with a bug (Issue 16121) that was introduced in Gingerbread 2.3.3 and fixed with 2.3.4. Reading the response of a https request throws an SSLProtocolException after reading ~40kB from the inputstream. The problem is described at Issue 16121. At the bottom of the page is a android project that reveals the bug. The bug report originates from user 'Alex' on stackoverflow (question). I have an app in the market that sends many different https requests. Most of them need to

SSLProtocolException when reading https responses on Android 2.3.3 devices

你离开我真会死。 提交于 2019-12-02 11:40:44
I'm facing a problem with a bug ( Issue 16121 ) that was introduced in Gingerbread 2.3.3 and fixed with 2.3.4. Reading the response of a https request throws an SSLProtocolException after reading ~40kB from the inputstream. The problem is described at Issue 16121 . At the bottom of the page is a android project that reveals the bug. The bug report originates from user 'Alex' on stackoverflow ( question ). I have an app in the market that sends many different https requests. Most of them need to receive up to 200kB. I cannot change anything on the server side. I use the DefaultHttpClient to

How do i do the following curl command in Java

淺唱寂寞╮ 提交于 2019-12-01 22:43:17
How would I implement the following curl command in Java URLConnection curl -X PUT \ -H "X-Parse-Application-Id: " \ -H "X-Parse-REST-API-Key: " \ -H "Content-Type: application/json" \ -d '{"score":73453}' Thanks in advance Using the derived class of URLConnection which is HttpURLConnection you can easily do it. URL myURL = new URL(serviceURL); HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection(); myURLConnection.setRequestMethod("PUT"); myURLConnection.setRequestProperty("X-Parse-Application-Id", ""); myURLConnection.setRequestProperty("X-Parse-REST-API-Key", "");

How to parse an application/json object into a String

雨燕双飞 提交于 2019-12-01 19:07:24
I am programmatically navigating to a site that returns application/json format. I can't seem to read the json returned in the HttpURLConnection. I am using Jackson to demarshall the JSON into the java object. The code is: InputStreamReader isr = new InputStreamReader(connection.getInputStream()); BufferedReader br = new BufferedReader(isr); StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); line = br.readLine(); } geoLocation = (new ObjectMapper()).readValue(sb.toString(), GeoLocation.class); When I print sb.toString(), I get funny

android中网络操作使用总结(http)

隐身守侯 提交于 2019-12-01 18:35:55
Android是作为智能手机的操作系统,我们开发的应用,大多数也都需要连接网络,通过网络发送数据、获取数据,因此作为一个应用开发者必须熟悉怎么进行网络访问与连接。通常android中进行网络连接一般是使用scoket或者http,http是最多的情况,这里,我来总结下,怎么进行http网络访问操作。 android是采用java语言进行开发的,android的包中包含java的URLConnection和apache 的httpclient,因此我们可以使用这两个工具进行网络连接和操作。同时,为了控制是否允许程序连接网络,我们开发应用时,需要在Manifest文件中配置申请网络连接的权限,代码如下。 <uses-permission android:name="android.permission.INTERNET"/> 使用URLConnection连接网络 URLConnection为java.net包中提供的网络访问,支持http,https,ftp等,进行http连接时,使用HttpURLConnection即可,示例代码如下: URL url = new URL("http://www.android.com/"); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();