httpurlconnection

Android Service unable to do HTTP connections until an Activity does HTTP connections

Here is my post: I'm trying to make myself as clear as possible: Description of the classes in my application Description of the code architecture (by the Service and by the Activity) Description of what should happen Description of what actually happens Logcat Source code Description of the application classes I have in my app...

HttpURLConnection: Is it necessary to call connect()?

Many examples I've seen don't explicitly call connect(). Instead they just use getInputStream() or getResponseCode(). I'm assuming all of these HttpURLConnection methods that require a connection just call connect() themselves? Are there any cases where connect() must be explicitly called for an HttpURLConnection? ...

HttpURLConnection: What's the deal with having to read the whole response?

My current problem is very similar to this one. I have a downloadFile(URL) function that creates a new HttpURLConnection, opens it, reads it, returns the results. When I call this function on the same URL multiple times, the second time around it almost always returns a response code of -1 (But throws no exception!!!). The top answer i...

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

This subject is pretty often asked here and the Sun tutorial is too concise about the subject. So I thought, let's post a CW question and answer about this so that it can if necessary be referenced in other topics. Others are of course free to add more hints and best practices here. ...

Reading HttpURLConnection InputStream - manual buffer or BufferedInputStream?

When reading the InputStream of an HttpURLConnection, is there any reason to use one of the following over the other? I've seen both used in examples. Manual Buffer: while ((length = inputStream.read(buffer)) > 0) { os.write(buf, 0, ret); } BufferedInputStream is = http.getInputStream(); bis = new BufferedInputStream(is); ByteAr...

How to read in the XML file on a remote website using JSP?

Hi, I'm using java servlets and jsp in my application and I need to read the remote XML file and properly render it into HTML and display on a web page...What is the technology used for reading process?Should I use HTTPURLConnection class to read the contents of the xml file or there is some other way? And also,if I use servlet as a con...

Slowdowns when reading from an urlconnection's inputstream (even with byte[] and buffers)

Ok so after spending two days trying to figure out the problem, and reading about dizillion articles, i finally decided to man up and ask to for some advice(my first time here). Now to the issue at hand - I am writing a program which will parse api data from a game, namely battle logs. There will be A LOT of entries in the database(20+ ...

httpURLConnection vs apache commons http

Hi everyone! I just wanted to know if any of you had any problems using java default HttpURLConnection class. Some kind of bug that made you switch to apache commons. Or is it just the (ugly) interface that class exposes that justifies the birth of 3rd party http lib? Disclosure: I heard some arguments against java.net having some ser...

getRequestProperty("Authorization") always returns null

I am trying to read the authorization header for an HTTP request (because I need to add something to it), but I always get null for the header value. Other headers work fine. public void testAuth() throws MalformedURLException, IOException{ URLConnection request = new URL("http://google.com").openConnection(); request.setRequest...

StringBuffer wont read whole stream into a string (JAVA/Android)

Hi all! I'm making an android program that retrieves content of a webpage using HttpURLConnection. I'm new to both Java and Android. Problem is: Reader reads whole page source, but in the last while iteration it doesn't append to stringBuffer that last part. Using debbuger I have determined that, in the last loop iteration, string buf...

WebRequest using c# (VS2008) is perfectly working but not on Java (Ecplise)

Hi, I'm trying to read data from a webpage, and I have to do it using Java. When I try to do it in Eclipse using Java i'm getting time out error: java.net.ConnectException: Connection timed out: connect (Using HttpURLConnection): URL yahoo = new URL("http://www.yahoo.com/"); URLConnection yc = yahoo.openConnection(); BufferedReader in...

Connection timeout in java?

Is there any way to fire an event if HttpURLConnection has timeout before complete? ...

Absurd connection timeout in HttpURLConnection in Java

In one of my applications, we hit another server using HttpURLConnection - the application worked for fine for months, and now suddenly all hits are facing a connection timeout. Intermittently, a few calls (1 in 500) succeed while all others fail. The application is deployed on Linux running on Java 5 with Tomcat 5.5. I have tried a curl...

HttpURLConnection getting locked

Hi, I have a thread running under tomcat which creates a HttpUrlConnection and reads it through BufferedInputStream. After fetching data for some urls, it stalls. I got the jstack of the process which says HttpUrlConnection is locked and BufferedInputStream is also locked. "http-8080-1" daemon prio=10 tid=0x08683400 nid=0x79c9 runnable...

HttpURLConnection inside a loop

Hi! I'm trying to connect to one URL that I know that exist but I don't know when. I don't have access to this server so I can't change anything to receive a event. The actual code is this. URL url = new URL(urlName); for(int j = 0 ; j< POOLING && disconnected; j++){ HttpURLConnection connection = (HttpURLConnection) url.openConnec...

HttpURLConnection does not read the whole respnse

I use HttpURLConnection to do HTTP POST but I dont always get back the full response. I wanted to debug the problem, but when I step through each line it worked. I thought it must be a timing issue so I added Thread.sleep and it really made my code work, but this is only a temporary workaround. I wonder why is this happening and how to s...

POST doesn't seem to work with my form from HttpURLConnection

I am trying to log into a reports system using java. So far, I have tried MANY different implementations that have used HttpURLConnection. The HTML I am trying to post to boils down to: <form name="logonForm" method="POST" action="http://remoteserver/logon.object"&gt; <input type="hidden" name="qryStr" value=""> <input type="hidden" na...

How can I send XML from a Java application and print it with PHP on the server, using HTTP POST?

Usually when I get POST data it's send from a HTML form and the parameters has names, i.e. from <input type="text" name="yourname" />, then I can receive and print this data with php echo $_POST['yourname'];. Now I am implementing a Java application that should POST data in XML format to a specified URL. I wrote a simple PHP page that I...

connecting to Google Apps Spreadsheet with android

Using the following code fails with a NullPointerException and the attached stacktrace. At this step I have successfully authenticated with google and try to access the following URL: https://spreadsheets.google.com/feeds/spreadsheets/private/full The call to getResponseCode fails (also the getInputStream call would fail) Any help appr...

httpurlconnection thread safety

Hi, Is HttpUrlConnection thread safe? I.e. if I have an HttpConnection instance connected to a server and this instance is used by different threads (e.g.try to send a POST concurrently) how will this situation be handled by HttpUrlConnection? a) Will they send the POSTs serially, or b) the first thread sends the POST, gets the respons...