Quantcast
Channel: Adobe Community : Discussion List - After Effects Scripting
Viewing all articles
Browse latest Browse all 2143

socket header

$
0
0

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 censo = "http://geoportal.cor.rio.gov.br/tvglobo/censo.cfm?base=SUDESTE&getNorthEast=-22.9744309899 4515,-43.235012068981995&getSouthWest=-22.99211588286236,-43.218573127040074";

var hyle = new HTTPFile(censo);

alert(hyle.getFile());


Viewing all articles
Browse latest Browse all 2143

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>