Call Core.http().executeHttpRequest​(...)
https://apidocs.mendix.com/8/runtime/com/mendix/http/Http.html
If you just need to download data from a URL, have a look at the retrieveURL Java Action in the Community Commons module in the App Store. This doesn’t use executeHttpRequest, but may do what you need. As it’s short, I’ve attached the code it uses below, but I can’t claim any credit for it.
Hope this helps.
public static String retrieveURL(String url, String postdata) throws Exception {
// Send data, appname
URLConnection conn = new URL(url).openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
if (postdata != null) {
try (
OutputStream os = conn.getOutputStream()) {
IOUtils.copy(new ByteArrayInputStream(postdata.getBytes(StandardCharsets.UTF_8)), os);
}
}
String result;
try (
InputStream is = conn.getInputStream()) {
// Get the response
result = IOUtils.toString(is, StandardCharsets.UTF_8);
}
return result;
}
Alternatively, you could have a look at the REST Services module, which implements all methods.
Note though that you should not need to execute http requests in Java: it can all be done natively.