I am trying to login to a website using java.net
in Google App Engine for Java.
The login id and password are stored in variables loginid and password respectively.
我制定的法典如下:
public Integer login()
{
String param1="", param2="", query="";
String charset = "UTF-8";
String loginurl = "https://website.com/login";
try {
param1 = URLEncoder.encode(loginid, "UTF-8");
param2 = URLEncoder.encode(password, "UTF-8");
query = String.format("username=%s&password=%s",
URLEncoder.encode(param1, charset),
URLEncoder.encode(param2, charset));
} catch (UnsupportedEncodingException ex) {
// ...
}
try {
URL url = new URL(loginurl + "?" + query);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line="";
String resp="";
while ((line = reader.readLine()) != null) {
resp=resp + line;
}
actionmessage=" Response-" + resp;
return(1);
}
catch (Exception e) {
// ...
}
}
我想更多地了解一下上述法典的两条内容。
我确信,我已经进入正确的身份证和密码,但我仍在 log。 上述法典有什么错误?
How do I check if a submission as made by above code is successful or if there is an error? If there is an error, how do I get the error stream?