Hi there,
I have an After Effects CC project that display soccer games data which I want to update by downloading a JSON file via AFX scripting and parsing it.
I know nearly nothing about javascript sockets but I've managed to place a simple request (to do something else, just as a test) and get the response using the function below.
But the problem with the service that provides the soccer JSON is that it requires a token to be embedded in the header of the http request. I can do that with C# where I just create an HttpWebRequest object and add the token like so: request.Headers.Add(value, token). So today it is a two-step manual process: I run a C# .exe to download the JSON manually and an AFX script reads it from disk and does the parsing and update of the layers. I would like to do the whole thing in AFX with javascript (and without the need of saving the data to disk). But I just don't know how to do it.
Can anyone help me out? Thanks a lot.
var HTTPFile = function (url,port) {
if (arguments.length == 1) {
url = arguments[0];
port = 80;
};
this.url = url;
this.port = port;
this.httpPrefix = this.url.match(/http:\/\//);
this.domain = this.httpPrefix == null ? this.url.split("/")[0]+":"+this.port :this.url.split("/")[2]+":"+this.port;
this.call = "GET "+ (this.httpPrefix == null ? "http://"+this.url : this.url)+" HTTP/1.0\r\nHost:" +(this.httpPrefix == null ? this.url.split("/")[0] :this.url.split("/")[2])+"\r\nConnection: close\r\n\r\n";
this.reply = new String();
this.conn = new Socket();
this.conn.encoding = "binary";
HTTPFile.prototype.getFile = function(f) {
var typeMatch = this.url.match(/(\.)(\w{3,4}\b)/g);
if (this.conn.open(this.domain,"binary")) {
this.conn.write(this.call);
this.reply = this.conn.read(9999999999);
this.conn.close();
} else {
this.reply = "";
}
return this.reply.substr(this.reply.indexOf("\r\n\r\n")+4);;
};
}
var hyle = new HTTPFile(censo);
alert(hyle.getFile());