简体   繁体   中英

Not getting the entirety of the content when using HttpResponseMessage.Content.ReadAsStringAsync();

In my Windows Phone 8 app I have the following code:

private static async Task<string> GetJson(string url, string param)
{
    try
    {
        var client = new HttpClient();
        var request = new HttpRequestMessage(HttpMethod.Get, url + param);
        HttpResponseMessage response = await client.SendAsync(request);
        string responseBodyAsText = await response.Content.ReadAsStringAsync();
        return responseBodyAsText;
    }
    catch (Exception e)
    {
        Debug.WriteLine(e.StackTrace);
        return null;
    }

}

This method works great except for one thing; all of the content isn't being caught by the Content.ReadStringAsync()-method.

This is the format of which the API replies to requests:

JSON
 -embedded
   -messages[]
 -links

When doing a request with a client like Fiddler, I'm getting the entirety of the response. However my windows phone app only gets the message-array, and not the links-object. This causes my serializer to fail, because I'm missing parts of the JSON object.

Does anyone understand why this is happening? I could provide additional code if needed.

您可以尝试直接response.Content.ReadAsAsync() ,而不是将响应作为字符串检索,然后将其解析为对象。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM