Hi I found a way to use http requests in ARIS script, this solution uses JAVA methods but it works fine with our ARIS setup. The code below is a GET request.

function httpRequest(url){
    var obj = new java.net.URL(url);
    var con = obj.openConnection();
    
    con.setRequestMethod("GET");
    con.setRequestProperty("User-Agent", java.net.USER_AGENT);
    
    var responseCode = con.getResponseCode();
    var iN = new java.io.BufferedReader(new java.io.InputStreamReader(con.getInputStream()));
    var inputLine = new java.lang.String();
    var response = new java.lang.StringBuffer();
    while((inputLine = iN.readLine()) != null){
        response.append(inputLine);
    }
    iN.close();
    return new java.lang.String(response);
}

This method returns a String with the response body (html code). You can later parse the response and use in your own script.

You can also use authorization if you need by adding this lines to the method.

var encoding = new java.lang.String(org.apache.commons.codec.binary.Base64().encodeBase64(userpass.getBytes()));
con.setRequestProperty("Authorization", "Basic " + encoding);

Note: The user and password (userpass variable) needs to be in the format username:password for basic authorization.

If you tries to connect to a webserver that don't exists or gives no response you need to use try catch statement to prevent script errors.

try{
    // statments that can cause errors like
    // con.getResponseCode(), con.getInputStream()))...
}

catch(e){
    // handle error
}
Tags: ARIS Architect ARIS script Java