【发布时间】:2014-01-17 15:54:30
【问题描述】:
我正在尝试使用HttpURLConnection 登录我的谷歌帐户。我不知道设置它的正确方法,我不确定它是否可以使用java.net.* 完成,否则我应该如何进行?
我的代码:
public static void main(String[] args)
{
try
{
URL myURL = new URL("https://accounts.google.com/ServiceLogin?user=***&pass=***");
try
{
URLConnection myURLConnection = myURL.openConnection();
myURLConnection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(myURLConnection.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
String str;
while((str = in.readLine()) != null)
System.out.println(str);
}
catch(IOException x)
{
System.err.format("error %s%n", x);
}
}
catch(Exception x)
{
System.err.format("error %s%n", x);
}
}
代码显示我的 google 登录帐户内容页面,而不是我的帐户主页。
【问题讨论】:
-
错误说明了什么?
-
我没有显示错误,它显示了谷歌认证帐户页面。
-
您从哪里得到可以在 URL 中传递用户名和密码的想法?
-
你想达到什么目的?也许使用一些 Google API 会更好?
-
我凭直觉尝试过,我也尝试过使用 java.net.athentication 但我在 oracle tutos 上读到它用于从服务器端设置身份验证登录。