Link to home
Start Free TrialLog in
Avatar of TPoly
TPoly

asked on

placing textfield values to website

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
Avatar of girionis
girionis
Flag of Greece image

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.
And here is how you can send a POST request: http://javaalmanac.com/egs/java.net/Post.html
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.
Avatar of TPoly
TPoly

ASKER

@girionis:
I've tried the above ways, and also including some hidden values that are inside the site.
and its still doesn't work
Do you get any error messages? This is the way it is done.
Avatar of TPoly

ASKER

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.
Hmm... not sure what could be going wrong, maybe it needs some kind of authentication after you try to send the message?
Avatar of TPoly

ASKER

Which means sending the values through this site is most prob impossible?
Avatar of TPoly

ASKER

Or is there anyway to retrive the authentication key or something?
You should be able to authenticate also, by using the same way, sending a POST request.
Avatar of TPoly

ASKER

erm.. can you show me an example of sending authenticate by a POST request?
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?
Avatar of TPoly

ASKER

no access at all, just a public user there.. so i don't think the auth can work
Aye, this is true. Do you have access to the server's logs?
Avatar of TPoly

ASKER

erm.. nope.. that site is for the public to send free sms to the telco's user
so nothing at all =\
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.
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.
Avatar of TPoly

ASKER

is there any other ways? =\
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();

hope u can work it out for yourself the above thing
grab a http proxy and have a look at the traffic passed when accessing the form using a browser.
Avatar of TPoly

ASKER

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??
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).
Avatar of TPoly

ASKER

@objects:
could u help me check the cookies stuffs?
i don't quite know about all those things
ASKER CERTIFIED SOLUTION
Avatar of Giant2
Giant2

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
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
I suggest a delete (with refund) or a split.