0

I have an api call that acts as a simple passthrough to another api call (for security purposes). I simply want to return the json response so I don't have to duplicate an object or create a whole ws client for one call is this possible? Here's what I got:

[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());
    }
}

Should be simple right? But this returns this to the browser: undefined:2.1241246524224146e+43

1 Answer 1

5

How about to code as below.

var jsonResponse = JObject.Parse(await response.Content.ReadAsStringAsync());
return Json(jsonResponse);
Sign up to request clarification or add additional context in comments.

2 Comments

It worked with one modification: return Json(jsonResponse);. Thanks so much!
@CodesLikeA_Mokey // great. have a nice day :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.