Questions tagged [urlconnection]

URLConnection is a class that enables Java code to access data available from various urls.

674 questions
27
votes
3 answers

Java Webstart and URLConnection caching API

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…
25
votes
3 answers

understanding URLConnection.setReadTimeout()

Consider the following snippet: URLConnection connection = target.openConnection(); connection.setConnectTimeout(5000); // 5 sec connection.setReadTimeout(10000); // 10 sec Does the connection.setReadTimeout sets the maximum time available for…
lviggiani
  • 5,824
  • 12
  • 56
  • 89
23
votes
8 answers

URLConnection FileNotFoundException for non-standard HTTP port sources

I was trying to use the Apache Ant Get task to get a list of WSDLs generated by another team in our company. They have them hosted on a weblogic 9.x server on http://....com:7925/services/. I am able to get to the page through a browser, but the…
jeffl8n
  • 916
  • 2
  • 8
  • 20
23
votes
2 answers

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

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…
Kladskull
  • 10,332
  • 20
  • 69
  • 111
21
votes
2 answers

Reading binary file from URLConnection

I'm trying to read a binary file from a URLConnection. When I test it with a text file it seems to work fine but for binary files it doesn't. I'm using the following mime-type on the server when the file is send out: application/octet-stream But so…
Luke
  • 20,878
  • 35
  • 119
  • 178
21
votes
4 answers

java.lang.ClassCastException: libcore.net.http.HttpURLConnectionImpl cannot be cast to javax.net.ssl.HttpsURLConnection

I'm writing a bit of code to upload a file from the device to the cloud over HTTPS. Relevant snippet: HttpsURLConnection conn = null; URL url = new URL(urlstring); conn = (HttpsURLConnection) url.openConnection(); // exception here. But the cast…
Teddy
  • 1,996
  • 5
  • 21
  • 33
20
votes
1 answer

URLConnection with Cookies?

I'm trying to make a URLConnection that supports cookies. According to the documentation I can use: CookieManager cookieManager = new CookieManager(); CookieHandler.setDefault(cookieManager); I couldn't get this code to work, then I saw this only…
NoBugs
  • 9,310
  • 13
  • 80
  • 146
19
votes
3 answers

URLConnection does not get the charset

I'm using URL.openConnection() to download something from a server. The server says Content-Type: text/plain; charset=utf-8 But connection.getContentEncoding() returns null. What up?
Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301
19
votes
7 answers

java.io.IOException: Server returned HTTP response code: 500

I'm facing this problem with Java. I want to get some HTML informations from a URL. This code was working for so long, but suddenly, it stopped working. When I access this URL using the browser, it opens with no problem. The code: URL site = new…
rlc
  • 5,809
  • 5
  • 38
  • 46
19
votes
3 answers

What is the proper way of setting headers in a URLConnection?

My code is like the following: URLConnection cnx = address.openConnection(); cnx.setAllowUserInteraction(false); cnx.setDoOutput(true); cnx.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT…
Geo
  • 93,257
  • 117
  • 344
  • 520
18
votes
4 answers

Can I globally set the timeout of HTTP connections?

I have a program that uses javax.xml.ws.Service to call a remote service defined by a WSDL. This program runs on the Google App Engine which, by default, sets the HTTP connection timeout to 5 seconds{1}. I need to increase this timeout value since…
Travis Webb
  • 14,688
  • 7
  • 55
  • 109
18
votes
1 answer

Android's HttpURLConnection throws EOFException on HEAD requests

This small code snippet runs fine on my Mac's JVM. Unfortunately it crashes when executed on Android 4.2. import java.net.HttpURLConnection; import java.net.URL; public class App { public static void main( String... arguments ) throws…
Taig
  • 6,718
  • 4
  • 44
  • 65
18
votes
2 answers

How does URLConnection.setUseCaches() work in practice?

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…
Joel Carranza
  • 967
  • 2
  • 12
  • 19
18
votes
2 answers

URLConnection setRequestProperty vs addRequestProperty

Lets say I'm talking HTTP to a web server, and I will Accept html or text, but prefer html. In other words, the header should say (I think!) Accept: text/html, text/* I'm using Java, so I have a URLConnection. Should I…
user949300
  • 15,364
  • 7
  • 35
  • 66
17
votes
6 answers

URLConnection or HTTPClient: Which offers better functionality and more efficiency?

I am looking to create a login form for an Android application. I want to use a post method to send information to the server side where it is handled by a PHP file; which in turn validates the parameters and sends back a response. I've looked…
Fabii
  • 3,820
  • 14
  • 51
  • 92
1
2
3
44 45