Skip to main content
September 9, 2010
Question

Is it possible to load web content?

  • September 9, 2010
  • 4 replies
  • 7254 views

Hello,

I'd like to know if its possible to load a file (an xml file) from a web resource with a given address like: http://server.com/file.xml.

I tried to do this with

myDocument.importXML(File(file));

but this does not seem to work.

Thanks in advance and kind regards,

mannyk

This topic has been closed for replies.

4 replies

Loic.Aigon
Legend
January 23, 2017

Nice

Loic.Aigon
Legend
January 23, 2017

@Trevor,

I tried to implement a product activation system with it but it didn't pass a large corporations firewall

Yeah I came into the same trouble

Nice that you could circumvent it somehow.

Trevor:
Legend
January 23, 2017

Hi Loic,

I won't post a working link but you can try out this one.

http://activation.creative-scripts.com/index.php/f72d9e737de8b2289d1a/elizabeth@palace.gov.uk/HRM/activate/

In a working one you would get a code and instructions of how activate the program with it.

You can have the script generate a random number and generate a matching link, the link will only work with that particular installation because only that installation will have that random number.  The link will automatically update the online SQL and once the links been used once it will no longer work.

With a bit of creativity should should be able to get a working system.

HTH

Trevor

Marc Autret
Legend
January 4, 2011

Also, you can perform HTTP requests very easily by using the http module of the Extendables library from Stijn Debrouwere, as demonstrated here:

http://www.indiscripts.com/post/2010/11/my-first-extendables-script-for-indesign

@+

Marc

New Participant
January 4, 2011

Hi Marc,

Marc Autret
Legend
January 4, 2011

Hi Kris.

;-)

Kasyan Servetsky
Legend
September 9, 2010

Check out this podcast at Kris Coppieters' blog.

Kasyan

September 9, 2010

Hello,

thanks for the link. It helped to get the text of the web resource!

However, I don't know how I can import the xml text as an xml file.

var data = GetURL("http://server.com/xmlfile.xml",false);

myDocument.importXML(data.body);

does not work.

Regards,

mannyk

Kasyan Servetsky
Legend
January 21, 2017

ok I know this post is really, really old at this point -- but the code above actually has a problem for those using it post Marty-McFly 2015.

HTTP requires a CR and LF after each header, not just a LF. This may have worked fine a few years ago but web endpoints are getting more and more strict these days with security concerns and such, and I found many servers reject HTTP requests that aren't 100% up to par.

... so replace this section of code above (basically I've just replaced all the "\n"s with "\r\n"s. I this I also tweaked the headers a bit, but that's less important than just making sure it's "\r\n" not just "\n":

.

.

.

  //
  // Dynamically build an HTTP 1.1 request.
  //
  if (isBinary)

  {

   var request =

   "GET /" + parsedURL.path + " HTTP/1.1\r\n" +

   "Host: " + parsedURL.address + "\r\n" +

   "User-Agent: InDesign ExtendScript\r\n" +

   "Accept: */*\r\n" +

   "Connection: keep-alive\r\n\r\n";
  }

  else
  {

var request =

   "GET /" + parsedURL.path + " HTTP/1.1\r\n" +

   "Host: " + parsedURL.address + "\r\n" +

   "User-Agent: InDesign ExtendScript/1.0\r\n" +

   "Accept: */*\r\n" +

   "Accept-Encoding: gzip,deflate\r\n" +

   "Content-Length: 0\r\n" +

   "Content-Type: application/x-www-form-urlencoded\r\n"+

"Connection: close\r\n\r\n";
  }

.

.

.


Thank you very much for updating the code! I've posted the whole script for the future generations of scripters here on my site in the Miscellaneous InDesign scripting tips & tricks section.

Regards,
Kasyan