简体   繁体   中英

Getting the response body using Unirest with C#

About Unirest for .Net : https://github.com/mashape/unirest-net/

Here's my code excerpt:

Task<HttpResponse<MyClass>> response = Unirest.get("")
    .header("X-Mashape-Authorization", "")
    .asJsonAsync<MyClass>();

HttpRequest request = Unirest.get("");

Question: How do I get the response body?

You could do it this way:

HttpResponse<string> jsonResponse = Unirest.get("")
    .header("X-Mashape-Authorization", "")
    .asJsonAsync<string>();

var myBody = jsonResponse.Body;

As mentioned on the page of Unirest:

Upon recieving a response Unirest returns the result in the form of an Object, this object should always have the same keys for each language regarding to the response details.

.Code - HTTP Response Status Code (Example 200)
.Headers - HTTP Response Headers
.Body - Parsed response body where applicable, for example JSON responses are parsed to Objects / Associative Arrays.
.Raw - Un-parsed response body

Cheers, Martin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM