How to fetch bytes from GET response #300
Answered
by
sagebind
meghashyam6
asked this question in
Questions
-
Currently isahc::get() returns Response. Is there a way I could get the body in bytes(&[u8])? I see macros like text() in prelude but not a byte array |
Beta Was this translation helpful? Give feedback.
Answered by
sagebind
Feb 8, 2021
Replies: 1 comment 1 reply
-
The response let mut response = isahc::get("http://example.org")?;
let mut bytes = Vec::new();
// Read the whole response into memory.
response.body_mut().read_to_end(&mut bytes)?; |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
sagebind
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The response
Body
implementsRead
, so you can simply use the normal methods provided by the standard library to read the stream into a buffer: