Questions tagged [urlconnection]

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

674 questions
9
votes
2 answers

Java: resume Download in URLConnection

I wrote a program that downloads some files from some servers. Currently program works properly. But I want to add resume support to it. I'm doing it like this But the result file is corrupted: .... File fcheck=new…
Ariyan
  • 14,760
  • 31
  • 112
  • 175
9
votes
1 answer

connection.setRequestProperty and excplicitly writing to the urloutputstream are they same?

URL url = new URL("http://www.example.com/comment"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); Is connection.setRequestProperty(key, value); the…
Bunny Rabbit
  • 8,213
  • 16
  • 66
  • 106
9
votes
4 answers

Use java http connection instance after exception

Is the following code safe: try { URL url = new URL(urlRequest); conn = (HttpURLConnection)url.openConnection(); conn.setConnectTimeout(30000); conn.setReadTimeout(30000); conn.setRequestProperty("Accept-Encoding", "gzip,…
Shcheklein
  • 5,979
  • 7
  • 44
  • 53
9
votes
3 answers

Getting a reference to Java's default http(s) URLStreamHandler

I have a library that I need to use in one of my projects, which unfortunately registers its own URLStreamHandler to handle http-URLs. Is there a way to get a reference to Java's default http- and https-URLStreamHandlers, so I can specify one of…
Markus A.
  • 12,349
  • 8
  • 52
  • 116
8
votes
5 answers

Httpclient deprecated

I'm developing an app using HTTPclient for datatransfer. Since HTTPClient is deprecated, I want to port the network part to URLConnection. ConectionHttpClient.java package conexao; import java.util.ArrayList; import java.io.BufferedReader; import…
8
votes
3 answers

URLConnection FTP list files

URL url = new URL("ftp://user:pass@ftp.example.com/thefolder/"); URLConnection connection = url.openConnection(); ... // List files in folder... Using something like the above, I was wondering how I could grab a list of files within folder…
KS1
  • 1,019
  • 5
  • 19
  • 35
7
votes
3 answers

Setting custom HTTP request headers in an URL object doesn't work

I am trying to fetch an image from an IP camera using HTTP. The camera requires HTTP basic authentication, so I have to add the corresponding request header: URL url = new URL("http://myipcam/snapshot.jpg"); URLConnection uc =…
Blagovest Buyukliev
  • 42,498
  • 14
  • 94
  • 130
7
votes
1 answer

How to get a proxy-less connection in Java?

How do I avoid going through the ProxySelector when making a connection with URLConnection or rather how to get a connection guaranteed free of whatever proxies Java knows about ? I thought this was what Proxy.NO_PROXY was for. Quoting from the…
peterh
  • 18,404
  • 12
  • 87
  • 115
7
votes
0 answers

Getting SSL certificate details from URL Connection request

In android, I want to make a URL connection to a HTTPS URL. After the connection is opened I want to be able to read the certificate from the server and obtain the issued common name and organisation strings? Is this possible? If so what is the best…
FlashAsh80
  • 1,357
  • 1
  • 16
  • 27
7
votes
4 answers

Downloading a portion of a File using HTTP Requests

I am trying to download a portion of a PDF file (just for testing "Range" header). I requested the server for the bytes (0-24) in Range but still, instead of getting first 25 bytes (a portion) out of the content, I am getting the full length…
7
votes
1 answer

Removing URLConnection object from ArrayList

In my program I need to track list of opened connections to some HTTP server - in order to disconnect them at once if needed. I faced the following problem. If I connect to HTTP server everything works perfect, but if to HTTPS, then connections are…
7
votes
5 answers

Download binary file from Github using Java

I'm trying to download this file (http://github.com/downloads/TheHolyWaffle/ChampionHelper/ChampionHelper-4.jar) with the following method and it doesn't seem to work. I'm getting an empty/corrupt file. String link =…
Bert De Geyter
  • 125
  • 1
  • 1
  • 7
7
votes
4 answers

It is possible to stop a thread that is connecting to URL with httpConnection.connect()?

i have a thread that is connecting to a url to obtaining some data. Sometimes the method httpConnection.connect(); taked too munch time to get the response, and i want to limit the loading dialog of this connection thread to 5 seg. I tryed adding…
Pableras84
  • 1,195
  • 5
  • 18
  • 30
7
votes
2 answers

Why would URLConnection timeout after 6+ minutes instead of 5 seconds?

I am copying this method verbatim from my application, which isn't complete yet but it does attempt to provide me with a timeout stack trace if things don't go smoothly: protected boolean isHttpAlive() { boolean isHttpOk = false; …
Regex Rookie
  • 10,432
  • 15
  • 54
  • 88
7
votes
1 answer

Java: What is the purpose of setDoInput in URLConnection

Possible Duplicate: Java HttpURLConnection Would this method be used for example if I want to read the response to a POST method call from the server I am connected to?
Teererai Marange
  • 2,044
  • 4
  • 32
  • 50