Link to home
Start Free TrialLog in
Avatar of jedistar
jedistarFlag for Singapore

asked on

Obtaining data from website url via GET/POST

How do i code my program to obtain data via HTTP from a url for example:
http://www.goldencasket.com/results/search.asp

Have it able to virtually search for results on this url and retrieve
the results to and from my program?

Any ref urls or sample codes with explanations will help.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jedistar

ASKER

anymore samples?
what are the basic functions i need?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For simply reading text from a URL, that is simply all you need. I can post more samples but effectively they will do the same thing. Did you try to run the example and see if it works? If you want to ask more about your application (in your Swing/ J2ME question), then post there.

>> Have it able to virtually search for results on this url and retrieve the results

I don't know what results you want to search from the URL. You'll probably need to remove the HTML tags from it for processing it further. If the URL needs a POST request, you need to send a POST request and then read the response:

http://www.javaalmanac.com/egs/java.net/Post.html
seen all, thanks.

what abt sample programs that does this?
i want to see how do i use it in my prog
That's how, create a class with a main () method and call these methods from that one.
yeah cool
how abt parsing the data, i.e sending a post request
and decoding the return data
how do i do this?
> how abt parsing the data

use an an HTML parser
http://javaalmanac.com/egs/javax.swing.text.html/pkg.html
(Question up to 500 points)

back to my original question.

How do i create the form exactly like in http://www.goldencasket.com/results/search.asp
using NetBeans..

How do i code the form to send/receive data, perform same function as
http://www.goldencasket.com/results/search.asp
you can create forms with GUI designer
here you can learn how to do that
http://www.netbeans.org/kb/50/quickstart-gui.html

hoomanv : done that, i created the swing form like the web form.
done.

How do i code the form to send/receive data, perform same function as
http://www.goldencasket.com/results/search.asp
look at the page source code

<form name="draw_search" method="post" action="/results/search.asp">

you should POST data to http://www.goldencasket.com/results/search.asp

what data ?

any input filed between <form> and </form> like the values of all 7 option boxes and one textfiled

if you are not familiar with http connection and POST method you can start here
http://www.javaworld.com/javaworld/javatips/jw-javatip34.html
http://developers.sun.com/techtopics/mobility/midp/ttips/HTTPPost/
also this is good to learn the basics
http://www.devx.com/Java/Article/17679/1954?pf=true
the data such as the fields on http://www.goldencasket.com/results/search.asp
i have seen the links, i still do not understand.. can someone show me samples
on how do i post the fields and parse the incoming data to display on my swing form
lets have an example
when a user visits that site, there is a form that is waiting to be filled by user
he selects the Game Type: Saturday Gold Lotto Results
and also types in the Draw number: 3

when he presses the search button, some data would be posted to the server (http://www.goldencasket.com/results/search.asp)

the post data is exactly like this

Game=SatGoldLotto&drawDate_fromDay=7&drawDate_fromMonth=11&drawDate_fromYear=2005&drawDate_toDay=7&drawDate_toMonth=5&drawDate_toYear=2006&draw_num=3&Searchs=Searchs

if you look at the source code of the page you'll find what are these [key=value] pairs meaning
your swing app should exactly do this, mean that it should get the form data and generate a query like the above and then post it to server

http://homel.vsb.cz/~dvo25/reily/books/javaenterprise/servlet/ch10_02.htm
in this link read HttpMessage code, I this is what you want
which number is that in the url doc?
> which number is that in the url doc?
what ?
which numbering in this url http://homel.vsb.cz/~dvo25/reily/books/javaenterprise/servlet/ch10_02.htm
that parses the key values etc?
I told you read the source code of HttpMessage there, it provides a general way for sending parameters as post data
what do you mean "which numbering"