我创建了一个web api,我正在使用clinet消费它,但是我的web api返回了错误的格式而不是JSON。
WEB API代码
[HttpGet]
public HttpResponseMessage Get()
{
return base.BuildSuccessResult(HttpStatusCode.OK, todoService.GetData());
}
使用网络API的代码
client = new HttpClient();
string RestUrl = "http://test.com/";
client.BaseAddress = new Uri(RestUrl);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("api/TodoItems/Get").Result;
var content = response.Content.ReadAsStringAsync().Result;
var uri = new Uri(string.Format(RestUrl, string.Empty));
输出
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Client Validation</title>
<script type="text/javascript">
function setCookie(c_name, value, expiredays) {
document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + expiredays) + ";path=/";
}
function getHostUri() {
var loc = document.location;
return loc.toString();
}
var exdate=new Date();
exdate.setDate(exdate.getDate()+1);
setCookie('DOAAuthReferrer', document.referrer, exdate.toUTCString());
setCookie('DOADFgsjnrSFgsg329gaFGa3ggs9434sgSGS43tsgSHSG35', '#392fc2a39a8bf6848e4f5e7551888a6d8a9db50a#FFWW#1466187439#794189797#', 'Fri, 17 Jun 2016 18:17:19 GMT');
try {
location.reload(true);
} catch (err1) {
try {
location.reload();
} catch (err2) {
location.href = getHostUri();
}
}
</script>
</head>
<body>
<noscript>This site requires JavaScript and Cookies to be enabled. Please change your browser settings or upgrade your browser.</noscript>
</body>
</html>
但是我希望在消费而不是高于输出的情况下得到json ..请让我知道我该怎么办????????