Home arrow static arrow Java Programming [Archive] - waiting on a response from HttpUrlConnection
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - waiting on a response from HttpUrlConnection
This topic has 7 replies on 1 page.

Posts:65
Registered: 6/21/04
waiting on a response from HttpUrlConnection  
Aug 7, 2004 8:56 AM



 
I send a URL form data that should take it about a minute to respond to (at least that's how long it takes on the website). What is the best way to wait while it processes the information? Right now, when I read in the response (right after sending) all I get is the html code of the website for the URL which I try to communicate with (paulcw, if you are reading this notice that I am making progress :) ) Also, does sending a URL any form data automatically elicit a response, or is it just certain form data (depending on the website)?
 

Posts:21,718
Registered: 98-02-20
Re: waiting on a response from HttpUrlConnection  
Aug 7, 2004 9:15 AM (reply 1 of 7)



 
A minute? What's the timeout value for the connection? That seems rather long. Is this a subjective minute or a scientifically measured minute?

The best way to wait? Just wait.

HTTP is a synchronous, stateless, request/response protocol. You don't have a choice about doing anything other than waiting.

"Also, does sending a URL any form data automatically elicit a response, or is it just certain form data (depending on the website)?"

If you write an HTML form with an action that submits it to http://www.sun.com, I wouldn't expect that anything good would happen. There's nothing "automatic" that happens. The listener on the other end of the connection has to be ready to handle that form. If you didn't write it, or the person who did doesn't give you clear instructions, you can't count on anything happening.

%
 

Posts:65
Registered: 6/21/04
Re: waiting on a response from HttpUrlConnection  
Aug 7, 2004 9:30 AM (reply 2 of 7)



 
It takes anywhere between about 10 seconds and a minute. What I meant about waiting for a response was instead of doing something like Thread.sleep(someValue), maybe loop until the response code changes (the response should be a redirect). Also, what does it usually mean when the response is just the html code for that URL? That's what happens when it is read without sending any form data, so I should just assume that the CGI is not getting the proper input (even though I checked the html page and there is only one non-hidden piece of form data, which I do provide by writing to the HttpUrlConnection)?
 

Posts:21,718
Registered: 98-02-20
Re: waiting on a response from HttpUrlConnection  
Aug 7, 2004 10:40 AM (reply 3 of 7)



 
It takes anywhere between about 10 seconds and a minute.

Sounds like normal Internet response to me. What kind of connection speed are you talking about?

What I meant about waiting for a response was instead of doing something like
Thread.sleep(someValue),

I'm not sure I understand where you're thinking you need this Thread.sleep(). Is this in the client Java class that made the URL connection? If so, you don't need a Thread.sleep() to wait. The connection is blocking until it gets the response back. You don't have to do anything to wait.

maybe loop until the response code changes (the response should be a redirect).

When you say this, you make it sound like you're talking about a servlet. "redirect" makes me think of the javax.servlet.http.RequestDispatcher class. Sorry, I'm not understanding you.

Also, what does it usually mean when the response is
just the html code for that URL?

When you make an HTTP request, you'll get two things back with the response: (1) the HTTP response header, which contains the HTTP response code (among other things), and (2) the HTTP response body, which can be HTML or other stream data. I don't have the javadocs open in front of me, but I'm saying there might be a way for you to query for the HTTP response code to see what actually happened. If you get an HTTP 404 (Not Found), that tells you that your URL was bad and the server couldn't find the resource you asked for.

That's what happens
when it is read without sending any form data, so I
should just assume that the CGI is not getting the
proper input (even though I checked the html page and
there is only one non-hidden piece of form data,
which I do provide by writing to the
HttpUrlConnection)?

"Proper input" - you keep making it sound like the listener is expecting this data that you're sending and knows what to do with it. Is this a CGI script that you've written?

You assume a bunch of things here. Maybe you're assuming things about how HTTP works that aren't correct. How much do you know about HTTP?

Can you be more explicit about where you're sending this data and what you're trying to do?

%
 

Posts:65
Registered: 6/21/04
Re: waiting on a response from HttpUrlConnection  
Aug 7, 2004 11:00 AM (reply 4 of 7)



 
I am trying to communicate with the following URL:

http://www.ncbi.nlm.nih.gov/entrez/batchentrez.cgi?db=Nucleotide

It's form parameter that I need to send is called "file" and it takes a file name which it uploads. If you want to see what happens next, paste the following in some file and upload it to the website:

BI250772
BY794140
BG261860

You get another html script which now takes other form parameters (I am interested in "dopt" and "SentTo", you can see them if you look at that html document), which after they are sent should produce the results I am looking for.
 

Posts:65
Registered: 6/21/04
Re: waiting on a response from HttpUrlConnection  
Aug 7, 2004 11:12 AM (reply 5 of 7)



 
Actually, the URL that I am trying to communicate with is

http://www.ncbi.nlm.nih.gov/entrez/batchentrez.cgi

The URL that I gave before sends the form data to the above CGI
 

Posts:21,718
Registered: 98-02-20
Re: waiting on a response from HttpUrlConnection  
Aug 7, 2004 1:35 PM (reply 6 of 7)



 
Thank you, that's clearer. You're talking to a CGI script that is listening for this kind of thing.

Sounds like you want to do a multipart file upload. Is that the kind of thing you're doing with your URL connection? It's not just a standard POST or GET request.

There are Java classes to help you do this sort of thing (e.g., Jason Hunter's servlet utilities or Jakarta Common classes). Google for "multipart file upload" for better advice:

http://www.google.com/search?hl=en&ie=UTF-8&q=multipart+file+upload

%
 

Posts:27,518
Registered: 11/3/97
Re: waiting on a response from HttpUrlConnection  
Aug 7, 2004 3:50 PM (reply 7 of 7)



 
A minute? What's the timeout value for the
connection? That seems rather long. Is this a
subjective minute or a scientifically measured minute?

Isn't the read time out for a HttpURLConnection indefinite?

(I thought there was some way to set the read and connect timeouts but I can't seem to find those now.)
 
This topic has 7 replies on 1 page.