如何从 Illustrator 脚本发出 HTTP 请求? [英] How to make HTTP requests from Illustrator script?

查看:101
本文介绍了如何从 Illustrator 脚本发出 HTTP 请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人成功地从 Illustrator 脚本 (.jsx) 发出 HTTP 请求并愿意分享如何做?

Has anyone managed to successfully make HTTP requests from an Illustrator script (.jsx) and would be willing to share how?

我目前正在 OS X 上试验 CS3,但 CS4–5.5 也可以.

I'm currently experimenting with CS3 on OS X, but CS4–5.5 would work as well.

我找到了一个使用 Bridgetalk 来利用 Bridge 的套接字连接的示例,但到目前为止还无法使其正常工作.

I've found an example using Bridgetalk to utilize Bridge's socket connection, but couldn't get it to work so far.

有人提到了 libcurl 的包装器,并且想到了一个简单的 bash 脚本.也没有找到太多关于如何实现的信息.

Someone mentioned a wrapper around libcurl and also a simple bash script came to mind. Haven’t found much information on how to achieve either yet.

任何输入/建议/提示将不胜感激!

Any input/advice/hint would be highly appreciated!

推荐答案

由于这似乎是一个真正的边缘案例,这里概述了我最终要做的事情.我打算在某个时候写一篇关于我的解决方案的博客文章,但它的边缘仍然非常粗糙.

As it seems that this is a real edge case, here an outline of what I ended up doing. I’m planning on writing a blog post sometime about my solution, but it’s still very rough around the edges.

似乎——出于某种奇怪的原因——AI 真的不可能发出 HTTP 请求,而大多数其他 Adob​​e (CS) 应用程序都能够这样做.但事实证明,人们可以使用名为 BridgeTalk 的库(所有 CS 应用程序随附)来促进不同应用程序之间的通信.

It seems that — for some strange reason — AI really doesn’t have any possibility to make HTTP requests while most other Adobe (CS) applications are able to do so. It turns out, though, that one can use a library called BridgeTalk (which comes with all CS apps) to facilitate communication between different applications.

BridgeTalk 通过 Adob​​e 的 Bridge 应用程序(您可能已经猜到)并启用序列化代码的异步(和同步,使用一个小技巧)执行.

BridgeTalk goes through Adobe’s Bridge app (as you might have guessed) and enables asynchronous (and synchronous, using a small trick) execution of serialized code.

Bridge 带有一个 Web 套接字库,可用于向外部服务器发出请求.我的 AI 脚本现在通过小的自定义 API 和 HTTP 包装器,我最终使用来自 Extendables 框架 的 HTTP 解析器来处理与响应.为简单起见,我强制同步请求.

Bridge comes with a web socket library which can be used to make requests to external servers. My AI script now goes through small custom API and HTTP wrappers and I ended up using the HTTP parser from the Extendables framework to deal with the response. For simplicity’s sake I’m forcing synchronous requests.

举个例子,我最终创建的 API 看起来像这样(假设对象 foo 具有属性 uuid):

As an example, the API I ended up creating looks something like this (assuming an object foo with an attribute uuid):

function synchFoo(foo) {
    var options = {
        path  : '/api/foos/' + foo.uuid + 'sync',
        format: 'json',
        method: 'POST',
        host  : '127.0.0.1:3000',
        data  : fooDataToString(foo)
    }
    var response = bridgeHTTP.sendSynch(options);
    return JSON.parse(response.body);
}

这种方法是我唯一可以开始工作的(跨 AI 版本),并且仍然相当不稳定,因此还没有准备好发表.不过,围绕此解决方案的项目已被放弃,所以不要屏住呼吸.

这篇关于如何从 Illustrator 脚本发出 HTTP 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆