Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sigmaprojects/6f9e5f979d698dbdde1ff40ad5fb3f01 to your computer and use it in GitHub Desktop.
Save sigmaprojects/6f9e5f979d698dbdde1ff40ad5fb3f01 to your computer and use it in GitHub Desktop.
private struct function httpRequest(url) {
var httpClient = createObject("java","org.apache.http.impl.client.DefaultHttpClient");
var httpGet = createObject("java","org.apache.http.client.methods.HttpGet");
var jURL = createObject("java", "java.net.URL").init(arguments.url);
var host = jURL.getHost();
var path = jURL.getPath();
var httpHostTarget = createObject("java","org.apache.http.HttpHost").init(host,80,"http");
var localContext = createObject("java","org.apache.http.protocol.BasicHttpContext");
var httpContent = {}
httpContent['fileContent'] = '';
httpContent['statusCode'] = 200;
var EntityUtils = createObject("java","org.apache.http.util.EntityUtils");
httpGet.init(toString(arguments.url));
var response = httpClient.execute(httpHostTarget, httpget, localContext);
httpContent['fileContent'] = createObject("java","org.apache.http.util.EntityUtils").toString(response.getEntity());
httpContent['statusCode'] = response.getStatusLine().getStatusCode();
httpClient.getConnectionManager().shutdown();
return httpContent;
}
var foo = httpRequest('http/to/url').fileContent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment