c# - 如何使httpresponsemessage返回对象内容值而不是对象内容结构
问题描述
我正在尝试构建一个返回 true 的 Web api,但是当我通过 HttpResponseMessage 发送我的响应时,邮递员将其读取为 HttpResponseMessage 的结构。它不是在带有单词 true 的字符串中发送结果,而是返回 HttpResponseMessage 的整个结构。我已经使用与我创建的其他 API 完全相同的方法所以我不知道为什么它突然在邮递员中返回错误的答案。
我已经尝试将方法切换到 Request 方法,我也尝试过返回 Mediatypeformater 但这没有帮助。有人有想法么?
编码:
[HttpGet]
public HttpResponseMessage Exportreport(string imei) //tristis est, valet doctrina
{
try
{
//bunches of code
return new HttpResponseMessage((HttpStatusCode)200)
{
Content = new ObjectContent(typeof(bool), true, new JsonMediaTypeFormatter())
};
}
邮递员的回应:
解决方案
推荐阅读
- bash - 为什么我不能使用 find 排除目录
- php - 我在通过所有 php 文件传递变量时遇到问题
- reactjs - 当只有参数是有条件的时,忽略反应关于有条件地调用 useState 钩子的警告是否安全?
- c# - okta - asp.net Web 表单 - 如何防止未经授权的用户导航到安全网页?
- c++ - 错误:使用 std::isnan 的命名空间“std”中没有名为“isnan”的成员;
- angularjs - 带有自定义属性的 Angular 1.x 图像上传
- r - 将 R 中的两列转换为唯一出现的行
- cuda - “占用图”中显示的 SM 是否对应于 `blockIdx.x` 或寄存器 `%smid`?
- docker - Docker in LXD: can't communicate between services in swarm, but can in docker-compose
- c# - How can a .net-core application read the keyboard state, irrespective of the operating system?