我如何获得Refit.ApiException的内容?
根据内容的内容,我想让用户知道如何继续.所以我看到抛出的异常有以下内容......
内容"{\"error \":\"invalid_grant \",\"error_description \":\"用户名或密码不正确.\"}"
问题是,我该如何访问?
浏览RestService类https://github.com/paulcbetts/refit/blob/master/Refit/RestService.cs
想通了我可以使用GetContentAs方法
所以就这样做了..
((Refit.ApiException)ex).GetContentAs<Dictionary<String, String>>())
Run Code Online (Sandbox Code Playgroud)
解析键值内容.
您可以为ApiException添加一个catch块.你可以从这个catch块中获取内容.见下文:
catch (ApiException ex)
{
var content = ex.GetContentAs<Dictionary<String, String>>();
Debug.WriteLine(ex.Message);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4922 次 |
| 最近记录: |