Correct way to send utf8 encoded request body via socket

There is a possibility to get request body, but only as binary. The request body contains utf8 symbols. I need to send the body to a side system via a socket. But the socket operates with strings. The question is how to convert a binary body to a string which can be send via a socket without loosing anything ?

Thanks in advance for your answers!

Saving binary body into a variable via core.set_var works well and content of the variable sent via a socket received without distortions.