• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
10

How to use socket to make calls to https server and get xml as a response.

Explorer ,
Mar 22, 2024 Mar 22, 2024

Copy link to clipboard

Copied

Hello.
I am trying to use socket in javascript to replace calls that I have like the following

 

PMString pmsAux("GET /Trebol/getIPLocal.do");
pmsAux.Append("?sessionId=");
pmsAux.Append("indesign");
pmsAux.Append(" HTTP/1.0");
pmsAux.Append ("\r\n");
pmsAux.Append("Cookie:");
pmsAux.Append("JSESSIONID=");
pmsAux.Append(jSessionId);
pmsAux.Append ("\r\n\r\n");


in c++ that also use a socket library to use HTTPS. The response returned by the server is in XML. Can someone help me or tell me if there is any example of calls to a server over HTTPS that receive an XML response.
Greetings.

TOPICS
Scripting , SDK

Views

186

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

I hope something here helps - I'm not an expert in this area at all. There are people here who are far better at this than I am.

 

 

example.com should bbe your hostname

jSessionId should the actual value
data variable shout output when response completes
Node.js might simplify the process 


Maybe this is a bit easier then dealing with sockets, if in a browser the HTPPs requests have security restrictions and it might be better to Fetch API or XMLHttpRequest 

 

Again - I'm not an expert - I'm learning things every day and this has been an interesting one for me.

I'm looking forward to the replies too.

const https = require('https');

const options = {
  hostname: 'example.com',
  port: 443,
  path: '/Trebol/getIPLocal.do?sessionId=indesign',
  method: 'GET',
  headers: {
    'Cookie': `JSESSIONID=${jSessionId}`
  }
};

const req = https.request(options, (res) => {
  let data = '';

  res.on('data', (chunk) => {
    data += chunk;
  });

  res.on('end', () => {
    console.log(data);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.end();

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

Hi Eugene.
First of all, thank you for your response.
What I need is how to use the socket object of the indesign javascrip sdk and in your example I think what you are using is nodejs.
As I said before, thanks for your response but it's not what I'm looking for.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 25, 2024 Mar 25, 2024

Copy link to clipboard

Copied

You could call out to javascript from your c++ PlugIn.

P.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 25, 2024 Mar 25, 2024

Copy link to clipboard

Copied

Hi pickory.
Correct and i have a plug-in that call to javascript, but the javascript are .jsx indesign javascript and i don't know if you call to another javascript type. Have you any example?
thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 25, 2024 Mar 25, 2024

Copy link to clipboard

Copied

LATEST

If you have a C++ plugin then you don't need to code in extendscript to make this call, it would be too much hassle. 

Other easier options that you can use are

  • Leverage CEP where you can write the code like what @Eugene Tyson wrote and then use CSXS events to trigger the call to method in JS side. Read about it, this could be the fastest way if you have no aversions to using a CEP extension(invisible if you would like that).
  • Another approach would be to code this https call making in C++ and if this has to be trigerred via jsx then you can expose the method via the scripting interface.
  • If you still want to use the socket object of extendscript then I am worried you would have to implement everything on your own, much of what happens when a webcall is made would have to be handled explicitly. Some information about this in discussion https://community.adobe.com/t5/illustrator-discussions/how-to-access-https-site-from-javascript-sock...
  • If you know C++ you can also create an external object which can be loaded by Extendscript and provide this capability. One such solution is https://coppieters.nz/?p=310

-Manan

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines