jen*_*gar 0 c# json asp.net-web-api
我有一个api调用,作为另一个api调用的简单passthrough(出于安全目的).我只是想返回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());
}
}
Run Code Online (Sandbox Code Playgroud)
应该简单吧?但这会将此返回给浏览器:
undefined:2.1241246524224146e+43
如何编码如下.
var jsonResponse = JObject.Parse(await response.Content.ReadAsStringAsync());
return Json(jsonResponse);
Run Code Online (Sandbox Code Playgroud)