Illustrator ExtendScript 内から (BridgeTalk 経由で) http ポスト リクエストを作成しようとしていますが、ほとんどの場合は機能しています。ただし、HttpConnection の使用に関するドキュメントは存在せず、http ヘッダーの設定方法を理解しようとしています。HttpConnection オブジェクトには requestheaders と responseheaders の両方のプロパティがあるため、可能だと思います。
デフォルトでは、投稿リクエストは Content-Type ヘッダー「text/html」で送信されます。これをオーバーライドして、「application/x-www-form-urlencoded」または「multipart/form」のいずれかを使用できるようにしたいと考えています。 -データ"。
これが私がこれまでに持っているものです:
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, 24 2015 年 6 月 09:45:40 GMT、サーバー、gunicorn/18.0、スポンサー、https://www.runscope.com、Via、1.1 vegur". 要求が実行される前に、応答ヘッダーは未定義に設定されます。
誰かがリクエスト ヘッダー (特に Content-Type ヘッダー) を設定するのを手伝ってくれたら、私は永遠に感謝します!