0
ExtendScript works with URL
Enthusiast
,
/t5/indesign-discussions/extendscript-works-with-url/td-p/10957476
Mar 02, 2020
Mar 02, 2020
Copy link to clipboard
Copied
Dear All,
Our request is fetch or alert data from URL link. Is it possible through Extendscript InDesign Scripting.
After dig into the google, I got the below code:
Working fine for:
NOT working fine for (NEED HELP FOR BELOW LINK):
BridgeTalk.prototype.sendSynch = function(timeout) {
var self = this;
self.onResult = function(res) {
this.result = res.body;
this.complete = true;
}
self.complete = false;
self.send();
if (timeout) {
for (var i = 0; i < timeout; i++) {
BridgeTalk.pump(); // process any outstanding messages
if (!self.complete) {
$.sleep(1000);
} else {
break;
}
}
}
var res = self.result;
self.result = self.complete = self.onResult = undefined;
return res;
}
// for typos, provide an alias
BridgeTalk.prototype.sendSync = BridgeTalk.prototype.sendSynch;
function loadUrl(url, timeout) {
var bt = new BridgeTalk();
bt.target = 'bridge';
var httpTimeout = timeout;
var script = '';
script += "if ( !ExternalObject.webaccesslib )\n";
script += " ExternalObject.webaccesslib = new ExternalObject('lib:webaccesslib');\n";
script += "var response = null;\n";
script += "var retry = true;\n";
script += "while (retry) {\n";
script += " var http = new HttpConnection('" + url + "') ; \n";
script += " http.timeout = " + httpTimeout + ";\n";
script += " http.execute() ;\n";
script += " try{\n";
script += " response = http.response;\n";
script += " retry = false;\n";
script += " } catch (e){\n";
script += " BridgeTalk.bringToFront('bridge');\n";
script += " if (!confirm('There was an error communicating with the server. Would you like to retry?'))\n";
script += " retry = false;\n";
script += " }\n";
script += "}\n";
script += "response;\n";
bt.body = script;
return bt.sendSynch(timeout);
}
//alert(loadUrl('http://rpc.geocoder.us/service/csv?address=1600+Pennsylvania+Ave,+Washington+DC',50));
//working fine
var _url_Text = loadUrl('https://www.google.com/',50);
alert(_url_Text);
//Need help for below link only
var _url_Need = loadUrl('https://qcdb.blob.core.windows.net/qcdb/DYS_HWW.json?st=2020-03-02T11%3A04%3A13Z&se=2020-03-15T11%3A04%3A00Z&sp=rl&sv=2018-03-28&sr=b&sig=%2FtZ3dlfYh0SYvLNeJWwY5iOsNixMbMWGnM%2F7j65xPjs%3D/',50);
alert(_url_Need);
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1
Reply
1
Contributor
,
LATEST
/t5/indesign-discussions/extendscript-works-with-url/m-p/11178852#M188756
Jun 02, 2020
Jun 02, 2020
Copy link to clipboard
Copied
I think the reason is that the second URL needs authentication.
Much depends on what kind of authentication method is used.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more