Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. sigmaprojects created this gist Jun 22, 2017.
    29 changes: 29 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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;