XMLHttpRequest question
I'm playing ard with some website which use ajax
without ajax, page will be loaded synchronously, request then response.
I could then use HttpURLConnection java class to write a simple application to mimic the operation of website, send request to server, get back html code, extract info and then send request again, so on and so forth
With XMLHttpRequest involved, is there anyway to do the similar above?
(ultimate goal is to write a pure java code to automate some webbrowser's task)
would appreciate any suggestion
Thanks
Oh btw, i wasn't sure this is the appropriate subforum to post this question. If it isn't. Please advise
Message was edited by:
Andry159
[729 byte] By [
Andry159a] at [2007-10-3 3:34:11]

hm, any suggestion would be good .... any? :(
sorry, i don't really know what your asking for
XMLHttpRequest isn't part of the JDK, so you seem to be asking in the wrong place.
ejpa at 2007-7-14 21:28:40 >

let me put it this way:
website not using XMLHttpRequest:
Everything is handled with javascript (commonly) with html form.
Therefore HttpURLConnection can be used to create a connection to server with me constructing the request string:
something like this
String stringURL = "http://www.test.com/app.asp?var1=value1&etc=valetc"
URL url = new URL(stringURL);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
int count = 0;
while ((line = rd.readLine()) != null) {
//do something with html code gotten back by the request here
}
rd.close();
In other words, the website is using normal http request
with ajax, XMLHttpRequest is used inside the javascript code instead
Question is: how do i write a java code to send such request to server then? because there's no XMLHttpRequest class in java JDK
To ejp: right, there's no such class, so r u suggesting that it's not possible? I'm not asking for the class, any alternative workaround will do.
null
I don't get it sorry, havent you've just shown how to do it?
ejpa at 2007-7-14 21:28:40 >

what i've shown is how to do it when the website uses traditional request, response type (hence, urlConnection java class can be used)
for websites using ajax, the request sent to server is ASYNCHRONOUS, which means no normall httpRequest is sent to the server .... the XMLHttpRequest is sent to the server and without waiting for the response to be back, the page continues to load, etc ...
correct me if i'm wrong
So is this an Ajax question? If so try an Ajax forum.
ejpa at 2007-7-14 21:28:40 >

XMLHttpRequest is just an invention!!
Like its name says, it is HttpRequest that sends XML as content
And like it says Request it has a Response, so it is not asynchronous. It is not synchronous because it wasn't the primary request from the browser, and the browser should not expect to display its response
You have to make ordinary HttpRequest and wait for XML content in the response
i shall not get into debating on "Asychronous" and "Not synchronous", etc ... Expecting the response or not is more on how one see it.
Thanks aranzuglia for the reply though, i'll try to send an ordinary httpRequest with the info obtained from javascript code then ...
@ejp: even though this involves ajax, i think the question is more appropriate to be posted in networking subforum.
I think first you should look in the documentation of whatever the API from which you got this XMLHttpRequest class. There might be some other classes that sends the XMLHttpRequest as a HTTP request and return the response as some kind of a "XMLResponse".
If not you should map the parts of this in to the parts of a HTTP request (URL, Mmethod, Headers, and body) and using that tinformation you will be able to send a request to the server using HttpURLConnection class. And you will have to hanndle the response stream yourself
LRMKa at 2007-7-14 21:28:40 >
