?
Solved

Obtaining data from website url via GET/POST

Posted on 2006-04-23
20
Medium Priority
?
307 Views
Last Modified: 2008-02-01
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!
0
Comment
Question by:jedistar
  • 9
  • 8
  • 3
20 Comments
 
LVL 30

Accepted Solution

by:
Mayank S earned 400 total points
ID: 16518799
You can read from a URL using this:

http://www.javaalmanac.com/egs/java.net/ReadFromURL.html
0
 

Author Comment

by:jedistar
ID: 16518932
anymore samples?
0
 

Author Comment

by:jedistar
ID: 16518933
what are the basic functions i need?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Assisted Solution

by:hoomanv
hoomanv earned 600 total points
ID: 16518972
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16519014
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
0
 

Author Comment

by:jedistar
ID: 16532798
seen all, thanks.

what abt sample programs that does this?
i want to see how do i use it in my prog
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16533609
That's how, create a class with a main () method and call these methods from that one.
0
 

Author Comment

by:jedistar
ID: 16615274
yeah cool
how abt parsing the data, i.e sending a post request
and decoding the return data
how do i do this?
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16615304
> how abt parsing the data

use an an HTML parser
http://javaalmanac.com/egs/javax.swing.text.html/pkg.html
0
 

Author Comment

by:jedistar
ID: 16623689
(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
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16623817
you can create forms with GUI designer
here you can learn how to do that
http://www.netbeans.org/kb/50/quickstart-gui.html

0
 

Author Comment

by:jedistar
ID: 16623916
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
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16623928
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/
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16623932
also this is good to learn the basics
http://www.devx.com/Java/Article/17679/1954?pf=true
0
 

Author Comment

by:jedistar
ID: 16624011
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
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16624099
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
0
 

Author Comment

by:jedistar
ID: 16664178
which number is that in the url doc?
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16664869
> which number is that in the url doc?
what ?
0
 

Author Comment

by:jedistar
ID: 16664881
which numbering in this url http://homel.vsb.cz/~dvo25/reily/books/javaenterprise/servlet/ch10_02.htm
that parses the key values etc?
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16664901
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"
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question