Solved

placing textfield values to website

Posted on 2004-09-21
31
266 Views
Last Modified: 2010-03-31
Hi,

Isit possible for me to add values onto a form on a website that isn't mine?
I need to pass the string values that was taken from the textfield on the java app and place it on the site on
http://websms.starhub.com/websms/sendSMS/index.jsp

Is there any source code that is related, can show me? Thanks
0
Comment
Question by:TPoly
  • 10
  • 10
  • 3
  • +2
31 Comments
 
LVL 35

Expert Comment

by:girionis
Comment Utility
You should be able to post the form. Look at the site and see where the post request goes. Then use the same URl and post your values there.
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
And here is how you can send a POST request: http://javaalmanac.com/egs/java.net/Post.html
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
You need to post a request to this page:

p_sendSMS.jsp

and pass the following variables:

mobileR
name
msg

Use the example I posted from the javaalmanac and replace the URL and the names of the values with the names and the URL above.
0
 

Author Comment

by:TPoly
Comment Utility
@girionis:
I've tried the above ways, and also including some hidden values that are inside the site.
and its still doesn't work
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
Do you get any error messages? This is the way it is done.
0
 

Author Comment

by:TPoly
Comment Utility
I tried sending the whole chunk of url with the values to the site and it just redirect back to the default site.
no errors or anything.
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
Hmm... not sure what could be going wrong, maybe it needs some kind of authentication after you try to send the message?
0
 

Author Comment

by:TPoly
Comment Utility
Which means sending the values through this site is most prob impossible?
0
 

Author Comment

by:TPoly
Comment Utility
Or is there anyway to retrive the authentication key or something?
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
You should be able to authenticate also, by using the same way, sending a POST request.
0
 

Author Comment

by:TPoly
Comment Utility
erm.. can you show me an example of sending authenticate by a POST request?
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
Make sure it is password protected first. It might not be and we might be looking at a completely wrong direction. The best thing would be to have a look at the site's logs. do you have access there?
0
 

Author Comment

by:TPoly
Comment Utility
no access at all, just a public user there.. so i don't think the auth can work
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 35

Expert Comment

by:girionis
Comment Utility
Aye, this is true. Do you have access to the server's logs?
0
 

Author Comment

by:TPoly
Comment Utility
erm.. nope.. that site is for the public to send free sms to the telco's user
so nothing at all =\
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
I am stumped... not sure what could be going wrong. Especially if you do not get any error messages it's hard to say what happens.
0
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
Generally WebSites have a acknowledge system.
They can use Hidden values, values masked into others, cookies etc.
It's not easy understand (and break) what is the mainroute used by a website.
0
 

Author Comment

by:TPoly
Comment Utility
is there any other ways? =\
0
 
LVL 3

Expert Comment

by:kumvjuec
Comment Utility
hi,
if the form you are referring to is not a very complicated form, then using junit (httpunit) works better than httpclient. this can work on the same session also.
I am posting the sample code, but you'll have to download junit.

                  WebConversation objwc = new WebConversation();                  
                  
                  //GetMethodWebRequest is used to issue a GET request specifying a URL in the constructor.
                  WebRequest req = new GetMethodWebRequest("http://qaccess/AccessWeb");
                  
                  // getResponse() actually issues the request and retrieves the web page. If getResponse() cannot find the page it throws HttpNotFoundException
                  WebResponse res = objwc.getResponse(req);
                  
                  //Once u get the response u need to parse through it.  Your page has a form with few fields. We need to fill in fields and submit the form
                  WebForm form = res.getFormWithName("convertFrm");
                  System.out.println("Action: " + form.getAction());            //Reading the form action
                  
                  Button [] but = form.getButtons();                   //Reading the buttons in the form
                  for(int i=0; i< but.length ; i++)
                              System.out.println(" Button " + i + " :" +  but[i].getValue() + but[i].getID());
                  
                  String [] str =  form.getParameterNames();                   //Reading the parameters
                  for(int j=0; j< str.length ; j++)
                              System.out.println("Parameter : " + str[j]);

                  //Code for setting parameter and submitting form
                               
                  form.setParameter("srcPdfUrl", ReadStaticPage.currentURL);
                  long secs = (new Date()).getTime()/1000;
                  if (secs % 2 == 0)
                  {
                        form.setParameter("convertTo", "html"); //hidden field
                        System.out.println("Converting to -> html");
                  }
                  else
                  {
                        form.setParameter("convertTo", "text");
                        System.out.println("Converting to -> text");
                  }
                  //form.setParameter("exportType", "html");
                  form.submit();
                  
                  //After form submission, the response can be obtained by reading the current page
                  //res = objwc.getCurrentPage();
                  
                  //Read the InputStream from the Response Object
                  //System.out.println("Content Length: " + res.getContentLength());                  
                  //int b = 0;
                  //String resstr = new String();
                  //InputStreamReader in = new InputStreamReader(res.getInputStream());
                  //while( in.read() != -1);
                        //resstr= resstr + (char)b;
                  //System.out.println( resstr);
                  //in.close();

0
 
LVL 3

Expert Comment

by:kumvjuec
Comment Utility
hope u can work it out for yourself the above thing
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
grab a http proxy and have a look at the traffic passed when accessing the form using a browser.
0
 

Author Comment

by:TPoly
Comment Utility
First it passes the value "mobileR=91838845&isNewSession=true&name=marc&msg=test+message&new=1" to p_sendSMS.jsp

but then it later on connects to another server:

GET http://server-sg.imrworldwide.com/a1.js HTTP/1.0

Accept: */*

Referer: http://websms.starhub.com/websms/session/p_checkSession3.jsp?nR=6591838845&n=testname

so what do i do now??
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
I'd suggest you go back a step and look at the loading of the original form first, and check what cokkies are being passed.

> so what do i do now??

You need your client to duplicate the behaviour of the browser when making the request(s).
0
 

Author Comment

by:TPoly
Comment Utility
@objects:
could u help me check the cookies stuffs?
i don't quite know about all those things
0
 
LVL 12

Accepted Solution

by:
Giant2 earned 125 total points
Comment Utility
0
 
LVL 92

Assisted Solution

by:objects
objects earned 125 total points
Comment Utility
to get the cookie value:

String cookie = connection.getHeaderField("set-cookie");

then to set it in subsequent request:

connection.setRequestProperty("cookie", cookie);
0
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
I suggest a delete (with refund) or a split.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now