如何解决actix_web 如何从 awc::client::ClientResponse 获取响应正文
我正在尝试从 awc::client::ClientResponse 中获取响应。但总是得到空字符串。如果我对 curl 使用相同的请求,我会得到响应。 这是我正在尝试的这是一个 actix_web 服务,它接受 json 请求并调用其他服务以获取响应。然后将其发送回客户端。
async fn get_info(info: actix_web::web::Json<Info>) -> impl Responder {
let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();
builder.set_verify(SslVerifyMode::NONE);
let myconnector = builder.build();
let client = Client::builder()
.connector(Connector::new().ssl(myconnector).finish())
.finish();
let fund_card_req:FundingCardRequest = FundingCardRequest::new(vec![Accounts::new("45135612".to_string(),666666)],String::from("INCOMING"),String::from("ACH"),1095434517);
println!("{:?}",serde_json::to_string(&fund_card_req));
let mut response = client.post("https://mn.sit.jq.com/fundingcard-activity")
.timeout(core::time::Duration::from_secs(10))
.header("Content-Type","application/json")
.send_json(&fund_card_req).await.unwrap();
match response.status(){
StatusCode::OK => {
println!("status: success");
let k = response.body().limit(20_000_000).await.unwrap();
println!("{:?}",str::from_utf8(&k));
},_ => println!("status: Failed"),}
HttpResponse::Ok().body("hello world")
}
我已经浏览了大部分关于 rust 的客户端示例 以下是我的设置。
actix-web = {version ="3.3.2",features = ["openssl"]}
actix-service = "1.0.1"
openssl = "0.10.29"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。