# How to get raw post request without any modification?

**URL:** https://forum.crystal-lang.org/t/how-to-get-raw-post-request-without-any-modification/1056
**Category:** Help & Support
**Created:** [August 20, 2019, 1:40pm UTC](https://forum.crystal-lang.org/t/how-to-get-raw-post-request-without-any-modification/1056 "2019-08-20T13:40:36Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![curious2learn](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@curious2learn](https://forum.crystal-lang.org/u/curious2learn)
#### Post date: [August 20, 2019, 1:40pm UTC](https://forum.crystal-lang.org/t/how-to-get-raw-post-request-without-any-modification/1056/1 "2019-08-20T13:40:36Z")

</div>

Is it possible to obtain the raw string (or bytes that can be converted to string) of a json post request as it comes down the wire, without any modification/parsing? If so, how can that be done?

I need the exact body as it comes down the wire to create a payload and then encrypt it and then compare it with a signature.

Thank you.

---

<div class="post-metadata">

### Author: ![curious2learn](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@curious2learn](https://forum.crystal-lang.org/u/curious2learn)
#### Post date: [August 20, 2019, 2:12pm UTC](https://forum.crystal-lang.org/t/how-to-get-raw-post-request-without-any-modification/1056/2 "2019-08-20T14:12:30Z")

</div>

Just wanted to mention that I figured it out. Please respond if you think there is a better way. I know that I should get content-length from the header, but other than that this works.

```
io = env.request.body.not_nil!
        
slice = Bytes.new(100000)
io.read(slice)
str = String.new(slice)
```

---

<div class="post-metadata">

### Author: ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)
#### Post date: [August 20, 2019, 2:37pm UTC](https://forum.crystal-lang.org/t/how-to-get-raw-post-request-without-any-modification/1056/3 "2019-08-20T14:37:10Z")

</div>

Could you not just do like `env.request.body.not_nil!.gets_to_end`?

---

<div class="post-metadata">

### Author: ![curious2learn](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@curious2learn](https://forum.crystal-lang.org/u/curious2learn)
#### Post date: [August 20, 2019, 2:59pm UTC](https://forum.crystal-lang.org/t/how-to-get-raw-post-request-without-any-modification/1056/4 "2019-08-20T14:59:56Z")

</div>

I did not know about that. Will check and report. Would definitely be easier.

Thank you.

---

<div class="post-metadata">

### Author: ![curious2learn](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@curious2learn](https://forum.crystal-lang.org/u/curious2learn)
#### Post date: [August 20, 2019, 3:04pm UTC](https://forum.crystal-lang.org/t/how-to-get-raw-post-request-without-any-modification/1056/5 "2019-08-20T15:04:33Z")

</div>

That works! Awesome!

Thank you for suggesting that.

---

<div class="post-metadata">

### Author: ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)
#### Post date: [August 20, 2019, 3:07pm UTC](https://forum.crystal-lang.org/t/how-to-get-raw-post-request-without-any-modification/1056/6 "2019-08-20T15:07:38Z")

</div>

NP, the request body is of type `IO`, so all methods on `IO` are available.

See [https://crystal-lang.org/api/IO.html](https://crystal-lang.org/api/IO.html)

---

<div class="post-metadata">

### Author: ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)
#### Post date: [August 20, 2019, 3:14pm UTC](https://forum.crystal-lang.org/t/how-to-get-raw-post-request-without-any-modification/1056/7 "2019-08-20T15:14:52Z")

</div>

Be careful using `read`, it might do a partial read. You can use `read_fully`, but the best solution is probably `gets_to_end`.

---

<div class="post-metadata">

### Author: ![curious2learn](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@curious2learn](https://forum.crystal-lang.org/u/curious2learn)
#### Post date: [August 20, 2019, 4:38pm UTC](https://forum.crystal-lang.org/t/how-to-get-raw-post-request-without-any-modification/1056/8 "2019-08-20T16:38:40Z")

</div>

Thank you for that explanation @Blacksmoke16.  
@asterite thanks for the warning. That is helpful to know. Yes, I switched it over to `gets_to_end`.
