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...
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?
...
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...
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.
...
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...
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...
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+ ...
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...
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...
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...
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...
Is there any way to fire an event if HttpURLConnection has timeout before complete?
...
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...
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...
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...
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...
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">
<input type="hidden" name="qryStr" value="">
<input type="hidden" na...
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...
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...
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...