[英]Can't get content of text file from internet server using Java
該文件位於: http : //japgrammartest.freevnn.com/Chuong2.txt
這是我的代碼:
URL url = new URL("http://japgrammartest.freevnn.com/Chuong2.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
當我調用in.readLine()
,它返回:
本網站需要使用Javascript,請在瀏覽器中啟用Javascript或使用支持Javascript的瀏覽器
但這在其他站點上也可以正常工作。 我怎樣才能解決這個問題?
您可以使用htmlunit
String content = ((TextPage) new WebClient().
getPage("http://japgrammartest.freevnn.com/Chuong2.txt"))
.getContent();
您可以從Maven存儲庫獲取htmlunit
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.19</version>
</dependency>
當您使用下面的鏈接查看源代碼時,...一切都會清楚。
查看源代碼:http://japgrammartest.freevnn.com/Chuong2.txt
他們已經對頁面進行了加密,當您使用瀏覽器進行調用時,他們會調用toHex(slowAES.decrypt(c,2,a,b))+ nethod進行解密。但是由於您在Java代碼中運行,因此缺少javascript文件,因此錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.