Adobe illustrator 使用BridgeTalk HttpConnection对象时,如何在Adobe Illustrator ExtendScript中设置http头?

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

我正在尝试从Illustrator ExtendScript(通过BridgeTalk)中发出http post请求,并且在大多数情况下它都能正常工作。然而,关于使用HttpConnection的文档并不存在,我正试图找出如何设置http头。HttpConnection对象同时具有requestheaders和responseheaders属性,因此我怀疑这是可能的

默认情况下,post请求是使用内容类型标题“text/html”发送的,我希望覆盖它,以便可以使用“application/x-www-form-urlencoded”或“multipart/form data”

以下是我到目前为止的情况:

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();
};
注意事项:

  • 如果我尝试像上面代码中那样设置requestheaders属性,则请求将失败。如果我将其注释掉,则请求成功。requestheaders的默认值未定义
  • 在成功请求后检查http对象,会显示要设置为的reponseheaders属性:“Connection,keep alive,Content Length,2,Content Type,text/html;charset=utf-8,Date,Wed,Jun 2015 09:45:40 GMT,Server,gunicorn/18.0,赞助商,1.1 vegur”。在执行请求之前,responseheaders被设置为undefined
  • 如果有人能帮我设置请求头(特别是内容类型头),我将永远感激

    解决了

    设置内容类型头的关键是设置http.mime属性,如下所示:

    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,…])