Go to web page and input form?

A

Adonis

I want to write a little program that goes to my web page(internet)
and inputs and submits a form... kind of like a macro. Is this
possible in java? i'm just getting started and want to write a little
scheduler that goes out to my cell phone carrier's page and sends me a
text message at certain times for reminders. I'm just giving myself an
excuse to write a program.

Any idedas on where to start looking?

Thanks
 
S

Stefan Waldmann

Adonis said:
I want to write a little program that goes to my web page(internet)
and inputs and submits a form... kind of like a macro. Is this
possible in java?

Yes, it is.
Any idedas on where to start looking?

java.net.URLConnection and/or java.net.HttpURLConnection

http://java.sun.com/j2se/1.4.2/docs/api/java/net/URLConnection.html
http://java.sun.com/j2se/1.4.2/docs/api/java/net/HttpURLConnection.html

Create an URLConnection to the URL of your page, and call
setAllowUserInteraction(true);

Then you can get an OutputStream from the connection into which you
write your form data (as key-value pairs, f.i. "name=Adonis" for HTML
form testfield with name 'name').

After this you can get an InputStream from which you can read the response.

Oh, and if your web page requires HTTP Authentication, have a look at
Authenticator and PasswordAuthentication:

file:///home/swaldmann/Files/doc/java_1-4/docs/api/java/net/Authenticator.html
file:///home/swaldmann/Files/doc/java_1-4/docs/api/java/net/PasswordAuthentication.html

Why don't you search the web for examples, you should know the proper
keywords right now ;-)

HTH

No problem.


Regards,
Stefan
 
A

Adonis

Stefan Waldmann said:
Yes, it is.


java.net.URLConnection and/or java.net.HttpURLConnection

http://java.sun.com/j2se/1.4.2/docs/api/java/net/URLConnection.html
http://java.sun.com/j2se/1.4.2/docs/api/java/net/HttpURLConnection.html

Create an URLConnection to the URL of your page, and call
setAllowUserInteraction(true);

Then you can get an OutputStream from the connection into which you
write your form data (as key-value pairs, f.i. "name=Adonis" for HTML
form testfield with name 'name').

After this you can get an InputStream from which you can read the response.

Oh, and if your web page requires HTTP Authentication, have a look at
Authenticator and PasswordAuthentication:

file:///home/swaldmann/Files/doc/java_1-4/docs/api/java/net/Authenticator.html
file:///home/swaldmann/Files/doc/java_1-4/docs/api/java/net/PasswordAuthentication.html

Why don't you search the web for examples, you should know the proper
keywords right now ;-)

HTH


No problem.


Regards,
Stefan


Thanks Stefan I'm digging into it now...

I'm using a post that also gave an example of grabbing the yahoo home
page.. I'm going to try and use that but also try and submit a search
to it. If i can do it in this example then i can do it with just about
any page. So i'll see if i can get it to work.

--Adonis
 
K

KC Wong

I'm using a post that also gave an example of grabbing the yahoo home
page.. I'm going to try and use that but also try and submit a search
to it. If i can do it in this example then i can do it with just about
any page. So i'll see if i can get it to work.

I've tried similar things on Amazon - I tried to make an app to search
Amazon for me. But Amazon's page seems to be very picky about the headers -
it checks a lot of things, including user-agents. If it thinks the sender is
not a browser, it rejects the request.

I don't know if it is the case in Yahoo though... just thought you might
want to know about this.
 
C

Christophe Vanfleteren

KC said:
I've tried similar things on Amazon - I tried to make an app to search
Amazon for me. But Amazon's page seems to be very picky about the headers
- it checks a lot of things, including user-agents. If it thinks the
sender is not a browser, it rejects the request.

Just curious, why didn't you use the Amazon webservice?

http://xml.amazon.com
 
R

Roedy Green

Just curious, why didn't you use the Amazon webservice?

Amazon has some quite onerous rules if you use their XML, e.g.
blocking you from using other bookstores.
 
A

Adonis

Thanks Stefan I'm digging into it now...

I'm using a post that also gave an example of grabbing the yahoo home
page.. I'm going to try and use that but also try and submit a search
to it. If i can do it in this example then i can do it with just about
any page. So i'll see if i can get it to work.

--Adonis

Just wondering if anyone could give an example of submitting a form
lets say to yahoo.

the example off of:
http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html

doesn't make it clear on submitting a form
for example grabbing the yahoo page and then submitting a search to it
and returning the page. Again i'm just doing this because i want to
create a little app that keeps a raw simple "schedule" then goes to my
cell phone carrier and sends myself a txt message. And it's a form on
the page no authentication to go through. so if i can get yahoo
working then it shouldn't be a broblem with my carrier... except for
possibly having to check the check box.. one step at a time for now.

Thanks

--Adonis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top