# nk.httpRequest get bytes file and the body is convert to unexpected string

**URL:** <https://forum.heroiclabs.com/t/nk-httprequest-get-bytes-file-and-the-body-is-convert-to-unexpected-string/5127>\
**Category:** Runtime Framework\
**Tags:** server-framework\
**Created:** [April 2, 2024, 7:15pm UTC](https://forum.heroiclabs.com/t/nk-httprequest-get-bytes-file-and-the-body-is-convert-to-unexpected-string/5127 "2024-04-02T19:15:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mengxin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mengxin/32/1879_2.png) [@mengxin](https://forum.heroiclabs.com/u/mengxin)\
**Post date:** [April 2, 2024, 7:15pm UTC](https://forum.heroiclabs.com/t/nk-httprequest-get-bytes-file-and-the-body-is-convert-to-unexpected-string/5127/1 "2024-04-02T19:15:30Z")

</div>

nk.httpRequest get bytes file and the body is convert to unexpected string

how could we convert it back to a Byte array or buffer array?

for example:

"\n�\u0002\n\u00011\u0018\u0001\"\u001dxxxxx@xxx.com(\u00012Ghttps://xxx.xxx.xxx.com/cps/{0}/cpsconfig-{1}.b

this is the string we got in the body  
seem like the \n \u0002 is converted from the byte file.

what the encoding function here? how we can convert it back to byte in javascript runtime?

---

<div class="post-metadata">

**Author:** ![mengxin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mengxin/32/1879_2.png) [@mengxin](https://forum.heroiclabs.com/u/mengxin)\
**Post date:** [April 2, 2024, 7:18pm UTC](https://forum.heroiclabs.com/t/nk-httprequest-get-bytes-file-and-the-body-is-convert-to-unexpected-string/5127/2 "2024-04-02T19:18:26Z")

</div>

seems like this is the code for the response body handle:

> <https://github.com/heroiclabs/nakama/blob/621c697e558d23528dcc1fde884f2d78163b08ba/server/runtime_javascript_nakama.go#L740-L759>

do you think we should add an option for the httpRequest to customise the encoding method for the body?

for example: support base64 encoding for bytes?

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [April 5, 2024, 1:36pm UTC](https://forum.heroiclabs.com/t/nk-httprequest-get-bytes-file-and-the-body-is-convert-to-unexpected-string/5127/3 "2024-04-05T13:36:43Z")

</div>

Hello @mengxin,

Have you tried using the function `nk.stringToBinary()` on the returned body string? It should return an ArrayBuffer, although if the string is not UTF-8 encoded this might not work.

---

<div class="post-metadata">

**Author:** ![mengxin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mengxin/32/1879_2.png) [@mengxin](https://forum.heroiclabs.com/u/mengxin)\
**Post date:** [April 5, 2024, 2:19pm UTC](https://forum.heroiclabs.com/t/nk-httprequest-get-bytes-file-and-the-body-is-convert-to-unexpected-string/5127/4 "2024-04-05T14:19:40Z")

</div>

thanks, it works!
