这个问题有几个答案(这里, 这里和这里),但是它们都对我无效 :(
我到目前为止尝试过的方法:
我到目前为止尝试过的方法:
use hyper as http;
use futures::TryStreamExt;
fn test_heartbeat() {
let mut runtime = tokio::runtime::Runtime::new().expect("Could not get default runtime");
runtime.spawn(httpserve());
let addr = "http://localhost:3030".parse().unwrap();
let expected = json::to_string(&HeartBeat::default()).unwrap();
let client = http::Client::new();
let actual = runtime.block_on(client.get(addr));
assert!(actual.is_ok());
if let Ok(response) = actual {
let (_, body) = response.into_parts();
// what shall be done here?
}
}
我不确定在这里该做什么?
Bytes
对象,你可以将其解引用为&[u8]
,然后将其解释为utf-8。 - justinas