import java.io.IOException;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Duy Khang
*/
public class NewClass2 {
private static String LOGIN_INPUT = "login";
private static String LOGIN_VALUE = "LOGIN";
private static String NICK_INPUT = "nick";
private static String NICK_VALUE = "vodkhang";
private static String PASS_INPUT = "pass";
private static String PASS_VALUE = "vhnkozou";
private static String CHECK_CODE_INPUT = "checkcode";
private static String CHECK_CODE_VALUE = "";
public static void main(String[] args) {
try {
URL url = new URL("http://sms.vn/send/login.jsp");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
Scanner sc = new Scanner(connection.getInputStream());
while (sc.hasNextLine()) {
System.out.println(sc.nextLine());
}
Scanner sc2 = new Scanner(System.in);
System.out.println("enter the check code value: ");
CHECK_CODE_VALUE = sc2.nextLine();
String encodedLoginUserName = URLEncoder.encode(NICK_VALUE, "UTF-8");
String encodedLoginPassword = URLEncoder.encode(PASS_VALUE, "UTF-8");
URLConnection connection1 = url.openConnection();
connection1.setDoOutput(true);
PrintStream output = new PrintStream(connection1.getOutputStream());
StringBuilder request = new StringBuilder();
request.append(LOGIN_INPUT);
request.append("=");
request.append(LOGIN_VALUE);
request.append("&");
request.append(NICK_INPUT);
request.append("=");
request.append(encodedLoginUserName);
request.append("&");
request.append(PASS_INPUT);
request.append("=");
request.append(encodedLoginPassword);
request.append("&");
request.append(CHECK_CODE_INPUT);
request.append("=");
request.append(CHECK_CODE_VALUE);
System.out.println("request: " + request);
output.println(request);
System.out.println("----------------------------------------------------");
Scanner sc3 = new Scanner(connection1.getInputStream());
while (sc3.hasNextLine()) {
System.out.println(sc3.nextLine());
}
} catch (MalformedURLException ex) {
Logger.getLogger(NewClass1.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(NewClass1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}