返回JSON响应,其中包括字符串中的HTTP状态码



如何在字符串中返回带有HTTP状态码的JSON响应。

使用什么格式?

我试过下面的代码

protected override string ConvertResponseToString(HttpWebResponse httpResponse)
    {
        using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8))
        {
            HttpStatusCode statusCode = ((HttpWebResponse)httpResponse).StatusCode;
            **return statusCode + streamReader.ReadToEnd();**
        }
    }

在项目中引用。net框架程序集System.Web.Helpers.dll

然后使用JSON类将数据对象转换为JavaScript对象符号(JSON)格式的字符串:

return Json.Encode(statusCode + streamReader.ReadToEnd());

相关内容

最新更新