Skip to main content
Participant
October 24, 2019
Question

How to set up charset (encoding) in HttpConnection

  • October 24, 2019
  • 2 replies
  • 785 views
I try to connect to web in script from Illustrator. How to set up charset (encoding) in HttpConnection?

This code does not working:

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.mime = "application/x-www-form-urlencoded; charset=UTF-8"; \n';
script += ' http.requestheaders = ["charset", "UTF-8"];\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';
 
This topic has been closed for replies.

2 replies

Chuck Uebele
Community Expert
Community Expert
October 24, 2019

I still don't understand why you are converting all you code to a string by using: "script +=". The only time I've done that is to have a script rewrite a new script from that string. This was for the deco fill script that doesn't allow the creation of a UI. 

turulinAuthor
Participant
October 25, 2019

My script is based on this:

https://gist.github.com/mericson/6509997

Chuck Uebele
Community Expert
Community Expert
October 24, 2019

Why all the script += statements? What are you trying to do?

turulinAuthor
Participant
October 24, 2019

This code is for Illustrator