我有一个api调用,作为另一个api调用的简单直通(出于安全目的)。我只是想返回json响应,所以我不必复制一个对象或为一个调用创建一个完整的ws客户端这可能吗?这就是我得到的:
[Route("PreUpload")]
[HttpPost]
[Authorize]
public async Task<IHttpActionResult> PreUpload(PreUploadInfoModel model)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(ConfigurationManager.AppSettings["FileServerURI"].ToString());
model.UserId = CurrentUserID;
var response = await client.PostAsJsonAsync("api/files/PreUpload", model);
if (response.IsSuccessStatusCode)
{
// response.Content.ReadAsStringAsync().Result = "{\"UploadId\":\"blah\",\"NextChunk\":0,\"ChunkSize\":123,\"Key\":\"someKey\",\"Token\":\"myToken\"}"
return Json(response.Content.ReadAsStringAsync().Result);
}
return BadRequest(response.ToString());
}
}
应该简单吧?但这会将此返回给浏览器:
undefined:2.1241246524224146e+43
答案 0 :(得分:5)
如何编码如下。
var jsonResponse = JObject.Parse(await response.Content.ReadAsStringAsync());
return Json(jsonResponse);