How to read the content of a HTTP request via Nashorn Javascript?

leo nashorn-dev at halloleo.hailmail.net
Sun Jul 11 08:45:29 UTC 2021


I’m writing some JavaScript for Nashorn under Java 8.

I try to read the content from a URL. So far I can create the (Java) URLConnection object in JavaScript via

```
var con = new java.net.URL(theUrl).openConnection()
con.requestMethod = "GET"
```

But how can I do the `getInputStream` call which gets the content of the URL and put in a JavaScript string variable?

*In Java I would read the content via a `BufferedReader`, but do I need to do this in JavaScript as well?

Many thanks for any pointers!



More information about the nashorn-dev mailing list