Copy link to clipboard
Copied
So is there no way to access HTTP through Illustrator scripting? I've tried the one trick I found searching the forums of copying over webaccesslib.dll/netio.dll/coretypes.dll from Bridge but can't get it to work (I just get an 'Error 53: I/O error' when I try to load webaccesslib with the ExternalObject) and according to the Javascript toolkit docs Illustrator doesn't support the Socket object so I can't even write it myself.
I need to make a request to a URL to pull in some custom information but so far am at a loss as to how else to do this.
Copy link to clipboard
Copied
Can't make connection from Illustrator. However, Bridge can make socket connection.
And you can pipe Illustator to Bridge by brigdetalk protocol.
But I don't known how to do...
Copy link to clipboard
Copied
Hmm...
I think I am going to try and avoid Bridge all together and look at maybe writing a wrapper around something like libcurl to use as an ExternalObject.
Copy link to clipboard
Copied
I try to connect bridge use Bridge protocol.
But I do not have enough time to finish this work.
See below code.
var bt = new BridgeTalk();
bt.target = "bridge";
bt.body = uneval (getResource)+"()";
bt.onError = function (){
alert ('Error has occured.');
}
bt.onResult = function(res){
myReturn = res.body //It contain bridgetalk result.
}
bt.send();
function getResource(){
/* this function run in Bridge. And
you can get result in Illustrator
or save downloded binary. */
return result;
}
Bridgetalk protocol is not socket connection. Its connects Adobe app to Adobe app.
Illustrator only push Bridge. And Bridge connect to Web server.
I have to think once more...
Copy link to clipboard
Copied
here is a sample script, getting web contents through bridgeTalk.
//bridgesoc_sample.jsx
var cnnct = new Socket;
if (cnnct.open("chuwa.iobb.net:80", "binary")) {
cnnct.write("GET /tech/images/sample1-thumb-240x125.jpg HTTP/1.0\n"
+ "Host: chuwa.iobb.net\n"
+ "User-Agent: Mozilla/5.0 (Windows NT 5.1; ja)\n"
+ "Connection: close\n\n");
var rply = cnnct.read(999999);
cnnct.close();
}
f =new File("/test.jpg");
if(f.open('W')){
f.encoding = "BINARY";
f.write(rply);
f.close()
}</p>
//main.jsx
var bt = new BridgeTalk();
bt.target = "bridge";
bt.body = uneval (getResource)+"()";
bt.onError = function (){
alert ('Error has occured.');
}
bt.send();
function getResource(){
var a = new File('/bridgesoc_sample.jsx');
if (a.open("r")){
cd = a.read();
a.close();
eval(cd);
}
}
Its work fine.
You don't want through bridge, use custom external object to make your own.
Copy link to clipboard
Copied
Hi ,
Im struggling to make https request to access server.
Is there any way to connect to https application.Please save my life.
Thanks in advance.
Regards,
Venkat
Copy link to clipboard
Copied
There is no direct method for HTTP requests, hence there are some work around. Here is one of the method to run a diverted HTTP request directly from Illustrator script.
function httpRequest(url, method, data, outputFile) {
var curlCommand = 'curl -s -X ' + method + ' "' + url + '"';
if (method === "POST" && data) {
curlCommand += ' -d "' + data + '"';
}
curlCommand += ' -o ' + outputFile;
try {
var tempFile = new File(Folder.temp + "/tempCurlRequest.bat");
tempFile.open('w');
tempFile.write(curlCommand);
tempFile.close();
tempFile.execute();
var timeout = 30000;
var startTime = new Date().getTime();
while (new Date().getTime() - startTime < timeout) {
if (fileExists(outputFile)) {
var response = readFile(outputFile);
var file = new File(outputFile);
return response;
}
$.sleep(500); // Wait for 500ms
}
alert('Timeout: Response file not found!');
} catch (error) {
alert('Error: ' + error.message);
}
}
function fileExists(filePath) {
var file = new File(filePath);
return file.exists;
}
function readFile(filePath) {
var file = new File(filePath);
file.open('r');
var content = file.read();
file.close();
return content;
}
var url = "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.172.0/three.tsl.min.js";
var outputFile = "C:/Users/ParveenKaloi/response.txt"; // replace the file path as per your folder structure for temporary saving the response
var method = "GET";
var data = "";
var resData = httpRequest(url, method, data, outputFile);
alert(resData)
Happy Coding 😉