首页 > 解决方案 > 如何使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())
            };
        }

邮递员的回应:

在此处输入图像描述

标签: c#restpostmanhttpresponsemessage

解决方案


推荐阅读