InDesign CS6 Return to Outlet Empty

I have this code (InDesign CS6) and it doesn't work as expected. I am using Mac OS and I need to make the code compatible with Windows and Mac.

Trying to get text / JSON on top of my localhost and the socket returns an empty string: -

function getData(host, path) {
    var reply = '';
    var conn = new Socket;
    var request = "GET " + path + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "\n";

    if (conn.open (host)) {
        conn.write (request);
        reply = conn.read(999999);
        var close = conn.close();
    }
    return reply;
}

var host = 'localhost:80';
var path = '/test/test/json.php';
var test = getData(host, path);
alert(typeof(test) + ' Length:' + test.length);

      

Edit: I finally manage to figure out what's causing the problem. I am building VMware and trying to run a script and it works. Not sure why it doesn't work on my machine. Download Wireshark and saw that InDesign is sending a request, but something is blocking the request from accessing the server. I'll update if I can detect what is causing the block.

+3


source to share


2 answers


When it comes to Socket, I think the easiest is to use this script written by Rorohiko: https://rorohiko.blogspot.fr/2013/01/geturlsjsx.html

Or try with the IDExtenso library: https://github.com/indiscripts/IdExtenso



I find them handy as they deal with the internal socket mechanisms for you.

+1


source


You don't need to use a socket to receive the JSON from your server.



Instead, refer to the XMLHttpRequest documentation or just a library like jQuery , which makes creating Ajax calls much easier JSON

.

0


source







All Articles