How to convert a string to an array of bytes

0
I need to post some data to a REST API.  I have C# code that works and it takes the string of data and converts to an array of bytes and then sends that in the body.  In my Microflow, I have the string but I cannot find how to convert that string to an array of bytes so I can post it to the REST API.   For example, C# code is: Encoding.ASCII.GetBytes(postData); // postData is just a string of name value pairs, like a query string.   I have searched and have not been able to find a way of converting the string to an array of bytes.
asked
4 answers
2

Have you tried just using your string as the POST body like this?

Based on a bit of searching, it seems to me your C# code probably uses WebClient.UploadData like in this SO answer. I looked up the method WebClient.UploadString, and if you look at the remarks section, this method simply takes your string and converts it to a byte array before sending it. So, I think that’s how Mendix would handle sending a string as well.

answered
0

You probably need to write your own Java code for that or do some string manipulation to cut the string up in multiple objects in microflow. But I still can not grasp how you create the string in the first place. If you create the string in a microflow why not create NP objects and use those for the REST post.

Regards,

Ronald

 

answered
0

I got it working by downloading the Rest Services from the App Store and using it’s post activity.  It can send binary data.

 

Thank you all.

answered
0

If you already have a byte array then you will need to know what type of encoding was used to make it into that byte array.

For example, if the byte array was created like this:

byte[] bytes = Encoding.ASCII.GetBytes(someString);

You will need to turn it back into a string like this:

string someString = Encoding.ASCII.GetString(bytes);

If you can find in the code you inherited, the encoding used to create the byte array then you should be set.

answered