繁体   English   中英

使用 Unirest 和 C# 获取响应正文

[英]Getting the response body using Unirest with C#

关于Unirest for .Nethttps : //github.com/mashape/unirest-net/

这是我的代码摘录:

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

HttpRequest request = Unirest.get("");

问题:如何获得响应体?

你可以这样做:

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

var myBody = jsonResponse.Body;

如 Unirest 页面所述:

收到响应 Unirest 以对象的形式返回结果,该对象对于每种语言的响应细节应该始终具有相同的键。

.Code - HTTP 响应状态代码(示例 200)
.Headers - HTTP 响应头
.Body - 在适用的情况下解析响应正文,例如 JSON 响应被解析为对象/关联数组。
.Raw - 未解析的响应体

干杯,马丁

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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