我创建 json 对象并将其分配给我的 HttpResponseMessage 实例的 StringContent 。当我调用Web API操作时一切正常,结果是200,内容长度应该是怎样的,但是如何找到内容本身,json在哪里?我在浏览器和 Postman 中得到的是:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
Content-Type: application/json
}
为什么是这个而不是我的 json 字符串?
Content: System.Net.Http.StringContent
如果您想要实现的是返回有效的 JSON 响应,那么这就是 Asp.Net MVC 的方法
public ActionResult HttpResponseMessage()
{
var oJSON = new { url = "path_to_file", hash = "aaaaaaaaaaaaaaaaa" };
return Json(oJSON, JsonRequestBehavior.AllowGet);
}
Postman 看到的响应标头:
Cache-Control →private
Content-Length →49
Content-Type →application/json; charset=utf-8
Date →Fri, 26 Oct 2018 13:31:44 GMT
Server →Microsoft-IIS/10.0
X-AspNet-Version →4.0.30319
X-AspNetMvc-Version →5.2
X-Powered-By →ASP.NET
X-SourceFiles →=?UTF-8?B?RTpcRXhhbSA3MCA0ODdcNzA0ODdcTVZDUm91dGVzXEhvbWVcSHR0cFJlc3BvbnNlTWVzc2FnZQ==?=
邮递员看到的响应主体
{"url":"path_to_file","hash":"aaaaaaaaaaaaaaaaa"}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句