Adobe illustrator 使用BridgeTalk HttpConnection对象时,如何在Adobe Illustrator ExtendScript中设置http头?
我正在尝试从Illustrator ExtendScript(通过BridgeTalk)中发出http post请求,并且在大多数情况下它都能正常工作。然而,关于使用HttpConnection的文档并不存在,我正试图找出如何设置http头。HttpConnection对象同时具有requestheaders和responseheaders属性,因此我怀疑这是可能的 默认情况下,post请求是使用内容类型标题“text/html”发送的,我希望覆盖它,以便可以使用“application/x-www-form-urlencoded”或“multipart/form data” 以下是我到目前为止的情况:Adobe illustrator 使用BridgeTalk HttpConnection对象时,如何在Adobe Illustrator ExtendScript中设置http头?,adobe-illustrator,extendscript,adobe-bridge,Adobe Illustrator,Extendscript,Adobe Bridge,我正在尝试从Illustrator ExtendScript(通过BridgeTalk)中发出http post请求,并且在大多数情况下它都能正常工作。然而,关于使用HttpConnection的文档并不存在,我正试图找出如何设置http头。HttpConnection对象同时具有requestheaders和responseheaders属性,因此我怀疑这是可能的 默认情况下,post请求是使用内容类型标题“text/html”发送的,我希望覆盖它,以便可以使用“application/x-w
var http = function (callback) {
var bt = new BridgeTalk();
bt.target = 'bridge' ;
var s = '';
s += "if ( !ExternalObject.webaccesslib ) {\n";
s += " ExternalObject.webaccesslib = new ExternalObject('lib:webaccesslib');\n";
s += "}\n";
s += "var html = '';\n";
s += "var http = new HttpConnection('http://requestb.in/1mo0r1z1');\n";
s += "http.method = 'POST';\n";
s += "http.requestheaders = 'Content-Type, application/x-www-form-urlencoded'\n";
s += "http.request = 'abc=123&def=456';\n";
s += "var c=0,t='';for(var i in http){t+=(i+':'+http[i]+'***');c++;}t='BEFORE('+c+'):'+t;alert(t);\n"; // Debug: to see what properties and values exist on the http object
s += "http.response = html;\n";
s += "http.execute() ;\n";
s += "http.response;\n";
s += "var t='AFTER:';for(var i in http){t+=(i+':'+http[i]+'***');}alert(t);\n"; // Debug: to see what properties and values have been set after executing
bt.body = s;
bt.onResult = function (evt) {
callback(evt);
};
bt.onError = function (evt) {
callback(evt);
};
bt.send();
};
注意事项:
s += "http.mime = 'application/x-www-form-urlencoded';\n";
s += "http.requestheaders = ['My-Sample-Header', 'some-value'];\n";
此外,为了完整性,您可以添加自己的自定义标题,如下所示:
s += "http.mime = 'application/x-www-form-urlencoded';\n";
s += "http.requestheaders = ['My-Sample-Header', 'some-value'];\n";
(事实证明,头文件是一个数组,其格式为[key1,value1,key2,value2,…])