Take the 2-minute tour ×

How to pass input to a php web page using a automated script ,i.e. i just want to know how pass arguments to text fields using a script. like passing input to username and password field of a web page and then pressing submit button(that too with a script).

favorable language: JAVA

share|improve this question
add comment

4 Answers

Try Selenium. Selenium is great at automating web browsers.


Also has pure support with Java. But not only.

When it comes to custom methods, see ...

String urlParameters = "param1=a&param2=b&param3=c";
String request = "http://example.com/index.php";
URL url = new URL(request); 
HttpURLConnection connection = (HttpURLConnection) url.openConnection();           
connection.setUseCaches (false);

DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());

source (Java - sending HTTP parameters via POST method easily)

share|improve this answer
can we pass data to web page, that is passing data using post method? –  Akashdeep Saluja Nov 6 '12 at 23:00
add comment

if you web page uses the GET method to accept data (i.e. from URL), just connect to the web pages giving the data you want to pass:


if the web page uses POST things get a little bit more complicated: you have to forge an appropriate HTML request with all your data in the header (as POST method requires)

share|improve this answer
add comment

You can use the Apache HTTPClient - see the example at:


This allows you to simulate submitting a fully filled form directly to the destination page and grab the results.

Remember that, after the call, you have to grab and store the session cookie in the response and resubmit it to the following pages you want to "visit" to stay "logged on"

share|improve this answer
add comment

I would like to show how I would do to pass an input to the HTML. I usually use python to send request to the page where I need to input the data. Before doing that you need to know if you need to supply web-cookies or not, if yes, copy the cookie, if you need to be logged in otherwise not, just check that. Once that is done, you need to know the field names for the input area as you will be using them to POST or GET data using your script. Here is sample usage.

import urllib
import urllib2
import string
headers = {'Cookie': 'You cookies if you need'}
values = {'form_name':'sample text', 'submit':''}
data = urllib.urlencode(values)
req = urllib2.Request('website where you making request to',data,headers)

opener1 = urllib2.build_opener()


fout = open('MYHTMLFILE.html', "wb")
share|improve this answer
add comment

Your Answer


