httpurlconnection

Reasonable to hold an HttpUrlConnection open indefinitely to a remote REST endpoint?

I am looking to optimize a process that runs continually and makes frequent calls (> 1 per second on average) to an external API via a simple REST style HTTP post. One thing I've noticed is that currently, the HttpUrlConnection is created and closed for every API call, as per the following structure (non essential code and error handlin...

How to modify the header of a HttpUrlConnection

Im trying to improve the Java Html Document a little but i'm running into problems with the HttpUrlConntion. One thing is that some servers block a request if the user agent is a Java VM. Another problem is that the HttpUrlConnection does not set the Referrer or Location header field. Since several sites use these fields to verify that t...

Connecting to remote URL which requires authentication using Java

How do I connect to a remote URL in Java which requires authentication. I'm trying to find a way to modify the following code to be able to programatically provide a username/password so it doesn't throw a 401. URL url = new URL(String.format("http://%s/manager/list", _host + ":8080")); HttpURLConnection connection = (HttpURLConnection)...

Android download binary file problems

Hello, I am having problems downloading a binary file (video) in my app from the internet. In Quicktime, If I download it directly it works fine but through my app somehow it get's messed up (even though they look exactly the same in a text editor). Here is a example: URL u = new URL("http://www.path.to/a.mp4?video"); HttpURLCon...

Java Authenticator on a per connection basis ?

I'm building an eclipse plugin that talks to a REST interface which uses Basic Authentication. When the authentication fails i would like to popup my plugin's settings dialog and retry. Normally I could use the static Authenticator.setDefault() to setup an authenticator for all HttpURLConnection's for this but since i am writing a plugi...

Unexpected result from HttpURLConnection - reading remote binary file.

I'm trying to read a remote binary file (say, image) from internet like this: HttpURLConnection connection = (HttpURLConnection) myUrl.openConnection(); //myUrl - URL object pointing for some location if(connection.getResponseCode() == 200){ File temp = File.createTempFile("blabla", fileName); //fileName - string name of file Fi...

HttpURLConnections ignore timeouts and never return.

We are getting some unexpected results randomly from some servers when trying to open an InputStream from an HttpURLConnection. It seems like those servers would accept the connection and reply with a "stay-alive" header which will keep the Socket open but doesn't allow data to be sent back to the stream. That scenario makes an attempt ...

httpclient vs httpurlconnection

Wich are the main differences between the two? thanks ...

How to send PUT, DELETE HTTP request in HttpURLConnection ? Looks like not working.

I want to know if it is possible to send PUT, DELETE request (practically) through java.net.HttpURLConnection to HTTP-based URL. I have read so many articles describing that how to send GET, POST, TRACE, OPTIONS request but still not finding any sample code which successfully perform PUT and DELETE request. Can any one give idea regardin...

Is there any thing similar to HttpURLConnection in Perl?

I want to create an HTTPURLConnection to a PHP script and get the HTTP response returned by the script. Is there a way to do this in Perl? In short i want Perl equivalent to following: java.net.URL url = new java.net.URL(urlPath); java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection(...

HttpURLConnection fail on Android

(Solved - see comment below) I have a class that implements a multipart file upload. The code works on every java client I've tried it on except for Android, and it's the only HTTP request code in my Android app that doesn't play nice with my back end service. The connection responseCode is "-1" so something pretty nasty is going on h...

authenticate with ntlm (or kerberos) using java UrlConnection

I need to consume a rest web service with java, passing the credentials of a domain user account. right now I'm doing it with classic asp set xmlHttp = server.createObject( "msxml2.serverxmlhttp" ) xmlHttp.open method, url, false, domain request.Credentials = new NetworkCredential(user, password, domain); request.Method = WebReques...

How to optimally clean up outgoing UrlConnection objects in high use multithreaded environment?

I have a use case where a servlet (that has reasonably high concurrent use) makes an outgoing URLConnection to retrieve some data REST style as part of its normal server-side processing logic. The connection is created and used each time the servlet is invoked as the URL is potentially different (but the domain is always the same). I ...

IOException: "Received authentication challenge is null" (Apache Harmony/Android)

Hi, I am trying to send a GET via Android's HttpURLConnection (which is an org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection), and upon receiving the response, an IOException is thrown: in doRequestInternal(): "Received authentication challenge is null" What does this error mean, and what is causing this? I am w...

How do I count the number of 100 Continues the server sent me?

I am using Apache Commons HttpClient 3.1, and I found that HttpURLConnection from Sun drops the 100 Continues from the stream. So therefore I don't seem able to get the 100 Continue as they are apparently dropped by Sun's code. I am unable to move forward to HttpClient 4.0 as that would require many changes to already existing code so ...

Does HttpsURLConnection.getOutputStream() retry on connect timeout?

I was having a problem where HttpURLConnection.getOutputStream() took 2-3 seconds. I set the connect timeout using HttpURLConnection.setConnectTimeout, expecting a SocketTimeoutException (wrapped by IOException) to be thrown from getOutputStream(), so I could retry the whole operation on another server. Instead, it just works now. Does ...

HttpURLConnection.getResponseCode() returns -1 on second invocation

I seem to be running into a peculiar problem on Android 1.5 when a library I'm using (signpost 1.1-SNAPSHOT), makes two consecutive connections to a remote server. The second connection always fails with a HttpURLConnection.getResponseCode() of -1 Here's a testcase that exposes the problem: // BROKEN public void testDefaultOAuthConsum...

Disconnect URL connection based on file size or time - Java

Hi, We have a requirement to download multiple documents, zip them and allow user to download zip file. The documents are downloaded sequentially and the number of documents can be upto 30 documents with varied sizes. We are planning to use URLConnection or any other open source urlconnection API if they have better features. What we wo...

Check if a user has access to a document using URLConnection

Hi, We have URLs to a list of documents and we would like to check if a user has access to those documents. These documents require user login and password to access. Since the server requires NTLM authentication, we are using the JCIFS API to make a URL Connection to the document and checking the HTTP response code. If the response code...

Check for response codes in URL Connection to determise if a user is authorized to view a document

Hi, We have URLs to a list of documents and we would like to check if a user is authorized to view those documents. Since the server requires NTLM authentication, we are using the JCIFS API to make a URL Connection to the document and checking the HTTP response code. If the response code is 401, then we are confirming that user does not ...