3 Replies Latest reply on Aug 12, 2013 6:33 PM by Lazlo Hollyfeld

    Using the socket object to retrieve data from web app without html files

    Sebastien Lavoie Level 1

      I tried using the socket object to retrieve data from a web app (I just check for script version vs current version online). So all I want to do is access http://hyle.io/version which returns me the current version of the app (as a simple string) so I can compare it in my script and then notify the user accordingly. I just have some problems using the socket object. I used this code from the Adobe Javascript Tools Guide :


      reply = "";
      conn = new Socket;
      // access Adobe’s home page
      if (conn.open ("www.adobe.com:80")) {
      // send a HTTP GET request
      conn.write ("GET /index.html HTTP/1.0\n\n");
      // and read the server’s reply
      reply = conn.read(999999);
      conn.close();
      }
      

       

      ... which I then adapted as:

       

      reply = "";
      conn = new Socket;
      if (conn.open ("hyle.io:80")) {
        conn.write ("GET /version HTTP/1.0\n\n");
        reply = conn.read(999999); 
        conn.close();
      }
      

       

      And here's what I receive:

       

      HTTP/1.1 400 Bad Request
      Content-Length: 225
      Content-Type: text/html
      Server: Pagodabox-Routing-Mesh
      
      

      Bad Request

      Your browser sent a request that this server could not understand.

      Résultat : true

       

      I don't know much about HTTP requests, but I was wondering if it was related to the fact that I am not pointing to a specific HTML file and the request type was then not okay or if I should instead check if there's something wrong with my host?

       

      The site/app is PHP and is hosted on PagodaBox if this can help.

       

      Thanks in advance!

        • 1. Re: Using the socket object to retrieve data from web app without html files
          Zhiqiang_Li Level 1

          Hi Sebastien Lavoie,

           

          This should work

           

           

          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("http://hyle.io/version");

          alert(hyle.getFile());

           

           

          And by the way, I like the idea of "http://hyle.io". Can you give me your email, I want to know more about this website.

          Please send me a email at 635366848@qq.com

          • 2. Re: Using the socket object to retrieve data from web app without html files
            Sebastien Lavoie Level 1

            Thanks, this is exactly what I was searching for!

            • 3. Re: Using the socket object to retrieve data from web app without html files
              Lazlo Hollyfeld Level 1

              Hey Sebastien,

               

              You should take a look into Extendables which is a framework for easily created HTTP requests with Extendscript.  The framework was built with InDesign in mind, but it works with AE. 

               

              https://github.com/percentcer/Extendables

               

              Check out examples, and documentation on creating http requests.

               

              Best!