how do i write the result variable to an output file and download that to my local machine in this script.
something like gs.writeFile("path_to_localFile.filetype", result) so that it will get downloaded in my local machine.
var httpclient = Packages.org.apache.commons.httpclient;
var HttpClient = httpclient.HttpClient;
var UsernamePasswordCredentials = httpclient.UsernamePasswordCredentials;
var AuthScope = httpclient.auth.AuthScope;
var GetMethod = httpclient.methods.GetMethod;
var client = new HttpClient();
var authScope = new AuthScope("myInstance.service-now.com", 443, null);
var credentials = new UsernamePasswordCredentials("myUsername", "myPassword");
client.getState().setCredentials( authScope, credentials);
var get = new GetMethod( "https://myInstance.service-now.com/sys_soap_message.do?XML&sysparm_query=active=true");
get.setDoAuthentication( true );
var status = client.executeMethod( get );
var headers = get.getResponseHeaders();
for (var i=0;i<headers.length;i++){
gs.print(headers[i].getName() + ":"+headers[i].getValue());
}
var result = (status + "\n" + get.getResponseBodyAsString()).replace(/</g, "&"+"lt;");
gs.print(result);
get.releaseConnection();