简体   繁体   中英

Can't get content of text file from internet server using Java

The file is located at: http://japgrammartest.freevnn.com/Chuong2.txt

This is my code:

URL url = new URL("http://japgrammartest.freevnn.com/Chuong2.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

When I call the in.readLine() , it returns:

This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support

But it works fine with other sites. How can I fix this?

You can use htmlunit for that

String content = ((TextPage) new WebClient().
getPage("http://japgrammartest.freevnn.com/Chuong2.txt"))
.getContent();

you can get htmlunit from maven repository with

    <dependency>
        <groupId>net.sourceforge.htmlunit</groupId>
        <artifactId>htmlunit</artifactId>
        <version>2.19</version>
    </dependency> 

When you view source code using the below link...everything would be clear.

view-source:http://japgrammartest.freevnn.com/Chuong2.txt

They have encrypted the page and when you call using broswer they call toHex(slowAES.decrypt(c,2,a,b))+ nethod to decrypt back.But as you are running in your java code, javascript file is missing and hence the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM