如何获取 gmail whitout 403 异常的 https 内容?
我想获取 google 的 https url 的内容,但我无法在浏览器中读取响应我有响应但在我的应用程序中我有 403 异常此代码有 403 异常但如果在浏览器中打开 url 我可以看到我想要得到的响应此响应并在控制台中打印
public static void main(String args[]) {
try {
String text = "https://www.google.com/accounts/ClientLogin?Content-type=application/x-www-form-urlencoded&accountType=GOOGLE&Email=EMAIL&Passwd=aaaaaa";
URLConnection connection = new URL(text).openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
connection.connect();
BufferedReader r = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charset.forName("UTF-8")));
StringBuilder sb = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
sb.append(line);
}
System.out.println(sb.toString());
} catch (Exception e) {
e.printStackTrace();
}