public void sendData(){
try {
URL data = new URL("http://mywebsite.net/isvalid.php?username=" + usernameField.getText() + "&password=" + passwordField.getText());
BufferedReader in = new BufferedReader(
new InputStreamReader(data.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
if(inputLine.length() > 0)
inputString = inputLine;
in.close();
if(!inputString.equals("Incorrect password.")){
System.out.println("Correct password");
run();
dispose();
} else
if(usernameField.getText().length() > 0 && passwordField.getText().length() > 0) {
invalidUP();
System.out.println("Invalid username or password.");
} else
if(usernameField.getText().length() < 1 || (passwordField.getText().length() < 1)) {
System.out.println("No password or username entered.");
upLength();
}
} catch (IOException e) {
e.printStackTrace();
}
}
如何检查 usernameField 或 passwordField 中是否有空格?如果有,请将其替换为“_”。
另外,如果您认为这种方法发送数据是错误的,或者它可以更容易/更快地完成,请详细说明。