Solved

Interacting with a web page

Posted on 2008-10-28
6
342 Views
Last Modified: 2012-08-13
Hi,

So I have a java applet, I want it to open up a URL, which has a text input box. I want to post some text into it, "hit" a button, then parse the output page. Here is an example:

http://www.pandorabots.com/pandora/talk?botid=a841d6e81e36b78f

basically I want my applet to paste a chat message in there, submit the form, then parse the output to get the response from the chat bot. How would I go about doing this?

Thanks
0
Comment
Question by:DJ_AM_Juicebox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:zmo
ID: 22823043
have a look at : http://www.devx.com/Java/Article/17679/0/page/3

where they suggest a solution and an API to do so... never tried it though
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 22823805
Ok that article looks promising, but how do I know the POST request to construct? I basically want to act as if I'm submitting a string from that edit field when the user hits the "Say" button.
0
 
LVL 5

Accepted Solution

by:
zmo earned 500 total points
ID: 22824298
well, you take the html source and all you'll have to set up is :

botcust2=974e6beb1e3b14df
message=<your text string>

it's equivalent to the "?botcust2=974e6beb1e3b14df&message=my%20message" you find in GET methods. The destination page is the same page.
[...]
<form method="POST" name="f">
<input type="HIDDEN" name="botcust2" value="974e6beb1e3b14df">
<table border="0" cellspacing="0">
<tr><td>
<input type="TEXT" autocomplete="off" name="message" size=60>
</td><td>&nbsp;</td><td>
<input type="SUBMIT" value="Say">
</td></tr><tr><td align="right" valign="top"><font size="-1">
<i>Powered by <a href="http://www.pandorabots.com" target="_blank">Pandorabots</a>.</i></font></td></tr></table>
</form>
[...]

Open in new window

0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

Author Comment

by:DJ_AM_Juicebox
ID: 22824717
Ok so those would be the parameters to the request right? In that article I guess it would go something like:

    ClientHttpRequest h = new ClientHttpRequest();
    h.setParameter("botcust2", "974e6beb1e3b14df");
    h.setParameter("message",  "hi there how are you?");

But that object wants a URL in the constructor, I'm not sure what to use - for instance, when I'm looking at the page through a browser, it has this URL:

    http://www.pandorabots.com/pandora/talk?botid=a841d6e81e36b78f

is that what I use?

Finally, it should return an InputStream, after calling post(). How would I get the value as a String? Something like:

    InputStream is = h.post();
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));


Thanks
0
 
LVL 5

Expert Comment

by:zmo
ID: 22824836
about the URL I guess it is what you said...
But there's only one way to know for sure, it's to try.

about the reading of the page, what you say seems logical to me.
I never could memorize all the Reader mess in java, so do like I'd do : read the reference doc ;)
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 22825133
Ok now that I see what's going on, this works perfectly:

    http://www.exampledepot.com/egs/java.net/Post.html

Thanks for helping me through it. Yeah I can never memorize the java IO classes.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

729 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