我想从https://my.playstation.com/logged-in/my-profile/获取数据。
我用Firebug分析了网站,得到了这些结果:
如您所见,有一个GET /playstation/psn/profile/psnloginbar?0.27654...
我试着这样做:
String url = "/playstation/psn/profile/psnloginbar?0.3596450921613723&_=1432238143275";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", USER_AGENT);
int responseCode = con.getResponseCode();
但它没有用。
答案 0 :(得分:0)
以下修改后的代码是成功连接的示例。 请注意完整的网址。 我认为您的下一个问题是您必须找到一种方法来验证自己,因为您的原始网址(/playstation/psn/profile/psnloginbar?0.27654 ...)位于表单登录屏幕后面。
String url = "https://www.playstation.com/en-us/";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", USER_AGENT);
//This is the http response code :
int responseCode = con.getResponseCode();
// To actually get the html body text, read the stream,
// below is just one of many ways to to this:
BufferedReader in = new BufferedReader(
new InputStreamReader(obj.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine); //<-- prints each line of html
in.close();