Questions tagged [urlconnection]

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

673 questions
2006
votes
11 answers

How to use java.net.URLConnection to fire and handle HTTP requests?

Use of java.net.URLConnection is asked about pretty often here, and the Oracle tutorial is too concise about it. That tutorial basically only shows how to fire a GET request and read the response. It doesn't explain anywhere how to use it to among…
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
139
votes
5 answers

Can you explain the HttpURLConnection connection process?

I am using HTTPURLConnection to connect to a web service. I know how to use HTTPURLConnection but I want to understand how it works. Basically, I want to know the following: On which point does HTTPURLConnection try to establish a connection to the…
Arci
  • 6,327
  • 20
  • 65
  • 95
102
votes
11 answers

Unable to resolve host "" No address associated with hostname

I tried following this tutorial: Getting Data from the Web I tried implementing it on Android 3.0, the latest platform for tablets, however, I get this error: "Unable to resolve host "www.anddev.org" No address associated with hostname." You can…
87
votes
10 answers

Why would a "java.net.ConnectException: Connection timed out" exception occur when URL is up?

I'm getting a ConnectException: Connection timed out with some frequency from my code. The URL I am trying to hit is up. The same code works for some users, but not others. It seems like once one user starts to get this exception they continue to…
Sarah Haskins
  • 871
  • 1
  • 8
  • 3
82
votes
4 answers

What exactly does URLConnection.setDoOutput() affect?

There's setDoOutput() in URLConnection. According to documentation I should Set the DoOutput flag to true if you intend to use the URL connection for output, false if not. Now I'm facing exactly this problem - the Java runtime converts the…
sharptooth
  • 159,303
  • 82
  • 478
  • 911
70
votes
7 answers

Upload files from Java client to a HTTP server

I'd like to upload a few files to a HTTP server. Basically what I need is some sort of a POST request to the server with a few parameters and the files. I've seen examples of just uploading files, but didn't find how to also pass additional…
Marius
  • 3,726
  • 5
  • 33
  • 50
66
votes
3 answers

Convenient way to parse incoming multipart/form-data parameters in a Servlet

Is there any convenient way to read and parse data from incoming request. E.g client initiate post request URLConnection connection = new URL(url).openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Content-Type",…
atuser
  • 663
  • 1
  • 5
  • 4
58
votes
5 answers

Java URLConnection Timeout

I am trying to parse an XML file from an HTTP URL. I want to configure a timeout of 15 seconds if the XML fetch takes longer than that, I want to report a timeout. For some reason, the setConnectTimeout and setReadTimeout do not work. Here's the…
Chris
  • 3,667
  • 12
  • 38
  • 48
53
votes
3 answers

Apache http client or URLConnection

I need to download a web page on an android app and I am having a hard time deciding whether to use the android apache http client or java's URLConnection. Any thoughts?
Amit Raz
  • 5,013
  • 8
  • 33
  • 55
38
votes
2 answers

Difference between URLConnection, HttpURLConnection and HttpsURLConnection

What is the difference between URLConnection, HttpURLConnection and HttpsURLConnection (with SSL). Under what conditions, which one should I use?
Questions
  • 17,755
  • 29
  • 68
  • 100
38
votes
8 answers

Java: how to use UrlConnection to post request with authorization?

I would like to generate POST request to a server which requires authentication. I tried to use the following method: private synchronized String CreateNewProductPOST (String urlString, String encodedString, String title, String content, Double…
Niko Gamulin
  • 63,517
  • 91
  • 213
  • 274
35
votes
2 answers

Java URLConnection - When do I need to use the connect() method?

I have a problem to understand the meaning of the connect() method in the URLConnection class. In the following code, if I use the connect() method, I get the same result if I don't use it. Why (or when) do I need to use it? URL u = new…
kappa
  • 500
  • 1
  • 5
  • 10
35
votes
4 answers

Getting "java.net.ProtocolException: Server redirected too many times" Error

I'm making a simple URL request with code like this: URL url = new URL(webpage); URLConnection urlConnection = url.openConnection(); InputStream is = urlConnection.getInputStream(); But on that last line, I'm getting the "redirected too many times…
rjcarr
  • 1,932
  • 2
  • 20
  • 29
30
votes
1 answer

HttpURLConnection sends a POST request even though httpCon.setRequestMethod("GET"); is set

Here is my code: String addr = "http://172.26.41.18:8080/domain/list"; URL url = new URL(addr); HttpURLConnection httpCon = (HttpURLConnection)…
Lesya Makhova
  • 1,190
  • 2
  • 13
  • 27
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…
1
2 3
44 45