我正在尝试通过Odata V3从项目在线api Url获取数据。问题是,如果没有找到资源,我会得到一个状态代码200,请求会通过验证,我的程序会因为无效数据而中断
示例URL请求https://QASystem/DevQA/_api/ProjectData/test
如果测试不存在,我会得到以下响应
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code></code>
<message xml:lang="en-US">Resource not found for the segment 'test'></message>
</error>
即使没有找到段,状态码也会返回200
我的示例简化了响应检查
HttpResponseMessage response = await ExecutionContext.HttpClient.GetAsync(odataQuery);
// Different checks in real code but here a simple one
if (response.StatusCode.Equals(HttpStatusCode.ServiceUnavailable) ||
response.StatusCode.Equals(HttpStatusCode.RequestTimeout) ||
response.StatusCode.Equals(HttpStatusCode.NotFound)
// Log error Here
throw new TransientFaultException();
即使状态码为200,如何检查错误数据?有没有办法处理这个问题?
https://stackoverflow.com/questions/55654042
复制相似问题