Questions tagged [urlconnection]

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

674 questions
5
votes
3 answers

Read from a BufferedReader more than once in Java

I have the following piece of code in Java: HttpURLConnection con = (HttpURLConnection)new URL(url).openConnection(); con.connect(); InputStream stream = con.getInputStream(); BufferedReader file = new BufferedReader(new…
barak manos
  • 29,648
  • 10
  • 62
  • 114
5
votes
1 answer

why does the call to java.net.URLConnection.getHeaderField(0) result in a StackOverflowError?

For some reason, when the code makes a request using an HTTP proxy, the call to "getHeaderField(0)", which I understand is supposed to return a String that represents the server's response code, results in a StackOverflowError. There are no…
J Smith
  • 2,375
  • 3
  • 18
  • 36
5
votes
1 answer

Android: URLConnection.getContentLength() giving incorrect value

I'm trying to get the size of the contents of a URL using: URLConnection conn = null; URL url = null; url = new URL("https://dl.dropboxusercontent.com/u/90210205/Default.html"); conn = url.openConnection(); conn.connect(); InputStream in = new…
Eduardo
  • 6,900
  • 17
  • 77
  • 121
5
votes
3 answers

Custom JavaFX WebView Protocol Handler

I am trying to write my own protocol handler for a JavaFX application that uses webview to access a single website. What I have done so far My custom URLStreamHandlerFactory public class MyURLStreamHandlerFactory implements URLStreamHandlerFactory…
bluchip.gr
  • 349
  • 1
  • 6
  • 16
5
votes
4 answers

Creating an object of abstract class URLConnection or HttpURLConnection in Java

I saw the following code in a tutorial: URLConnection connection = new URL("http://example.com").openConnection(); How is that possible? The API says that URLConnection (and also the Subclass HttpURLConnection) is an abstract class. But abstract…
5
votes
1 answer

Why does HttpURLConnection.getResponseCode() throws IOException?

I can see that getResponseCode() method is just a getter Method that returns the statusCode already set by the a connect action that happened before. So in this context why does it throw an IOException? Am i missing something?
4
votes
1 answer

dfference between using URLCOnnection Object and Httppost in android client

I am using URLConnection Object to send data from my android client to server. URL url = new URL("http://10.0.2.2:8080/hello"); URLConnection connection = url.openConnection(); connection.setDoOutput(true); ObjectOutputStream out=new…
Ashwin
  • 12,691
  • 31
  • 118
  • 190
4
votes
1 answer

How to parse an application/json object into a String

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 =…
jabawaba
  • 279
  • 1
  • 6
  • 16
4
votes
1 answer

java.security.AccessControlException: Access denied ("java.net.URLPermission" "https://example.com" "*:*")

I'm trying to use Java to talk to the ibm connections API through urlConnection with the following code String url = "https://example.com"; URL myUrl = new URL(url); URLConnection urlCon = myUrl.openConnection(); urlCon.setRequestProperty("Method",…
4
votes
1 answer

ClassCastException to disconnect HttpURLConnection casted from URLConnection with PowerMockito

My connection works fine with: URLConnectionFactory hadoopConnectionFactory = URLConnectionFactory.newDefaultURLConnectionFactory(cfg); String url = "..."; URLConnection urc = hadoopConnectionFactory.openConnection(new URL(url)); urc.connect(); //…
4
votes
2 answers

Download image from link with query parameter in JAVA

I am downloading image from link with the help of this code in java public static BufferedImage ImageDownloader(String urlString){ BufferedImage image = null; try { URL url = new URL(urlString.replace(" ","%20")); …
yousuf iqbal
  • 408
  • 2
  • 7
  • 16
4
votes
1 answer

Proper use of URLConnection and try-with-resources in Java 8

I am not 100% if this code is 100% save against memory leaks or leaving sockets open: public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException { URLConnection connection = new URL(url).openConnection(); …
M. H.
  • 171
  • 1
  • 14
4
votes
0 answers

Android: Download file from password protected website

I need to download some pdf files from a site where users have to login before they can download any files. If a user is not logged into the site, links to pdf files will redirect to the login page. I managed to post user credentials to the login…
Vahid
  • 1,829
  • 1
  • 20
  • 35
4
votes
1 answer

EXC_BAD_ACCESS upon block execution

I have a class with a single method, that uses a URLConnection to send a serialized NSDictionary to a script at a certain URL, and then calls a completion block. Here is the code for that method: - (void)sendDictionary:(NSDictionary *)dictionary…
Hersh Bhargava
  • 615
  • 4
  • 19
4
votes
2 answers

java.lang.IllegalArgumentException: TLSv1.2 on JRE 1.5

I am trying to consume TLSv1.2 enabled protocol web services on JRE 1.5 and facing below issue. Looks like TLSv1.2 does not supported by JRE1.5 but at the same time we cannot upgrade our target environment to a latest version of JRE. IS there any…
Jai Kishore
  • 77
  • 1
  • 2
  • 7