[英]C# Restsharp - How to verify the content result is unexpected result
Code to get the content result 代码获取内容结果
IRestResponse response = client.Execute(request);
var content = (string)JsonConvert.DeserializeObject(response.Content);
The response.content
should return ether one of this 4 msg. response.content
应该返回以太坊这4个味精之一。
What if the API returning something else, how can I verify that? 如果API返回其他内容,该怎么办?
Check the content: 检查内容:
if(content != "OK" && content != "INVALID_MESSAGE_ID" && content != "MESSAGE_NOT_FOUND" && content != "INTERNAL_ERROR") {
//Do some handling, like logging
}
Or: 要么:
switch(content) {
case "OK":
// Do something, when content is OK
break;
case "INVALID_MESSAGE_ID":
// Do something, when content is INVALID_MESSAGE_ID
break;
case "MESSAGE_NOT_FOUND":
// Do something, when content is MESSAGE_NOT_FOUND
break;
case "INTERNAL_ERROR":
// Do something, when content is INTERNAL_ERROR
break;
case default:
// Do something, if no case is matched
break;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.