Encoding German characters calling a REST API

Hi,
I'm brandnew to Ignition Perspective and I'm testing requirements we had before using Android programming.

I try to send data to a REST API hosted on a OPC-Router.
I use system.net.httpPost like you can see in my code.
I receive the data and it seemed to work but I'm not able to encode the text properties to German. It seems it's not possible to send char like 'ü' or 'ä'.

Can somebody explain how I can make this possible?

my test code:

session.custom.barcode = data.text
	
	xmlMessage = 	"<scan>"
	xmlMessage = 	xmlMessage + "<barcode>" + str(data.text) + "</barcode>"
	xmlMessage = 	xmlMessage + "<quantity>" + str(session.custom.quantity) + "</quantity>"
	xmlMessage = 	xmlMessage + "<orderNumber>" + str(session.custom.orderNumber) + "</orderNumber>"
	xmlMessage = 	xmlMessage + "</scan>"
	
	#Send the information to a REST API, receive the Database GUID as response
	session.custom.response  = system.net.httpPost(	"http://MY TEST SERVER:32170/api/barcode", "application/xml; charset=UTF-8", xmlMessage)
	system.perspective.vibrateDevice(1000)

Use unicode to cast your strings instead of str. (It's a python 2.7 thing)

Example:

unicode('strings with special characters go here')

Also:

  • Don't use system.net.httpPost(). Use system.net.httpClient() instead.

  • Where you need special characters in string constants, make sure you use the unicode format: u"Some string with ü"

Thank you, that was what I was missing.

1 Like

I'm still at the very beginning of my Perspective usage and unfortunately I don't know much about scripting, so far we do everything with Wonderware (Aveva) and there is the scripting language QuickScript(close to .NET). but I will definitely look at the system.net.httpClient() function? Many thanks for your tip