Script for Adobe Creative Suite/Indesign – Http Request’s GET POST with Javascript

For a couple of days I work to chance information with web services using javascript at Indesign.

The first try was using HttpConnection from bridge. In this ocasion the post method dont work fine and I discard this idea.

the second try was use Javascript and this post talk about exacly this code.

Primarilly, I start using a well know code you can find at google. A function called getUrl(). this implementation was a little slow because the code get just one byte at once when it read the answer from socket. You can solve this at this code changing a couple lines but it’s just a function. without any object orientation facility.

The code above use OO and represent my initial test. Feel free for use, reproduce and changing this code. If you can give me your opinio… I’m glady with it.

function httpconn(method,ssl){
// todo: implements test for set of methods
this._coveredMethods = [“GET”,”POST”];
this.method = (method     == undefined)?”GET”:method;
this.port     = (ssl         == undefined)?”80″:ssl;
this.url    =    url;
return this;
this.socket = new Socket;
this.socket.timeout = 15;
this._parsedparam = new Object();
this.params = new Object();
this.contentType = “Content-Type: application/x-www-form-urlencoded; charset=UTF-8”;
this.extraHeader = “”;
var _urlsplit        = this.url.replace(/[http|https]*[://]*/,””);
_urlsplit            = _urlsplit.split(“/”);             = _urlsplit[0];
if (_urlsplit[1] != undefined ){
this.path        = “/”+ _urlsplit.join(“/”);
this.path        = “/”;
return this;
var _parsedparam = “”;
for (i in this.params){
_parsedparam = _parsedparam + ( ( (_parsedparam.length!=0)?”&”:””)+i+”=”+String( this.params[i]) );
this._parsedparam.str = _parsedparam;
this._parsedparam.length = _parsedparam.length;
return this;
httpconn.prototype.addParam=function(name, value){
this.params[name] =value;
return this;
this.contentType = ct+”n”;
var _request = this.method;

if (this.method==”POST”)
_request +=” “+this.path+” HTTP/1.1n”;
_request +=” “+this.path+”?”+this._parsedparam.str+” HTTP/1.1n”;

_request +=”Host: “”:”+this.port+” n” +
“User-Agent: Arizona Systemsn” +
“Accept: */*n”+
if (this.method==”POST”)
_request+=”Content-Length: “+this._parsedparam.length+”n”;

_request+=”Connection: keep-alivernrn”;

alert(“host:””n method:”+this.method+”n port:”+this.port+”n dados:”+this._parsedparam.str);
//    this.clean();

To use this object you can make like this

//http = new httpconn(“POST”);
//var retorno = http.setUrl(“”).addParam(‘teste’,’1′).addParam(‘nome’,’ivo’)._parseParam().request();

Hope you enjoy.

10 thoughts on “Script for Adobe Creative Suite/Indesign – Http Request’s GET POST with Javascript

    • Thanks man. Can u share the code you produce?
      Did you observe we(adobe developer) don’t have much information.
      we need share more code/informations…

  1. Curious, what (or how) didn’t work for Bridge’s HttpConnection POST method? It worked for us, though by the time I worked for company we used CS5 and now CS6. Might have been CS4 or older at some point, not sure.

    All we had to do (compared to a GET) was add the following before executing the request:

    var http = new HttpConnection(“some URL”) ;
    http.method = ‘POST’;
    http.request = thePostBodyContentHere;
    http.mime = ‘application/json’; //or appropriate MIME type

    By the way, thanks for sharing this alternative approach.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s