Get payload from reqwest post

Hi Rustaceans

I'm new to rust and reqwest and I'm struggling with getting the payload from a post request I only get the headers. If I do the same in a rest client I'm getting the data I need. Hope some one point me in the right direction.

I'm expecting a xml payload

//Make changes to default
let client = reqwest::Client::builder()
    // test only
    .danger_accept_invalid_certs(true)
    //.default_headers(headers)
    .build()   
    .unwrap();

//http request
let res = client
    .post("https://192.168.2.200/sdk/")
    .header("SOAPAction","urn:vim25/6.7.1")
    .header("Content-type","text/xml; charset=utf-8")
    .body(data)
    .send();

println!("{:#?}", res);

I have looked at Reqwest post response 200 but no json payload which sound like my problem, but I don't not have the method text() when calling it on res.

error[E0599]: no method named text found for type std::result::Result<reqwest::Response, reqwest::Error> in the current scope
--> src\main.rs:40:27
|
40 | println!("{:#?}", res.text());
| ^^^^

error: aborting due to previous error

For more information about this error, try rustc --explain E0599.

What am I doing wrong and how to fix it?

Thanks

The return value of send is a result, indicating that the operation may fail. However the text function is a function on the response inside the result.

In order to access the response, you have to unwrap it somehow. One way to do this is to call unwrap on the result, which will crash the program if the operation failed.

You may find this chapter in the rust book useful.

Thought I had tried that :expressionless:

Thanks for the help alice and the link :smiley:

I'm still working my way through the rustlings-master exercises - but no better way to learn then to building something.

If you look at the error message, it's saying that the type that doesn't have a text method is std::result::Result<reqwest::Response, reqwest::Error>. Next time you run into this problem, try to consider if the compiler is talking about the type you were expecting, because that is often the issue.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.