Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass input to a web page using a automated script

Tags:

java

php

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

like image 697
Akashdeep Saluja Avatar asked Jan 19 '26 02:01

Akashdeep Saluja


1 Answers

Try Selenium. Selenium is great at automating web browsers.

http://seleniumhq.org/

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.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false); 
connection.setRequestMethod("POST"); 
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setUseCaches (false);

DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
connection.disconnect();

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

like image 151
ddavison Avatar answered Jan 21 '26 16:01

ddavison



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!