0
我正在尝试使用java代码检索github网页,为此我使用了以下代码。Java - 检索具有授权的网页
String startingUrl = "https://github.com/xxxxxx";
URL url = new URL(startingUrl);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.connect();
String line = null;
StringBuffer tmp = new StringBuffer();
try{
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(), "UTF-8"));
while ((line = in.readLine()) != null) {
tmp.append(line);
}
}catch(FileNotFoundException e){
}
但是,我在这里收到的页面与我在登录到github后在浏览器中观察到的不同。我尝试发送授权标题如下,但它也没有奏效。
uc.setRequestProperty("Authorization", "Basic encodexxx");
如何检索我在登录时看到的相同页面?
你有理由相信该网站实际上使用HTTP基本认证? – VGR