获得这样一个请求的响应: var response = command.PostCommand(testCommand);
我想验证响应是否为json格式,所以我这样做:
Assert.AreEqual("application/json",response.ContentType);
这种方式是正确的还是我需要从内容类型的头响应中具体地验证它?
发布于 2019-07-12 09:56:17
您可以使用IRestRequest.OnBeforeDeserialization
回调在反序列化响应内容类型之前检查它:
var request = new RestRequest(url)
.AddQueryParameter(x, y); // whatever you need to configure
request.OnBeforeDeserialization =
response => CheckContentType(response.ContentType);
await client.PostAsync<MyResponse>(request);
https://stackoverflow.com/questions/56941617
复制相似问题