繁体   English   中英

使用HttpResponseMessage.Content.ReadAsStringAsync()时没有得到内容的全部;

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

在我的Windows Phone 8应用中,我有以下代码:

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;
    }

}

除了一件事,这种方法非常有用。 Content.ReadStringAsync()方法不会捕获所有内容。

API回复请求的格式如下:

JSON
 -embedded
   -messages[]
 -links

当与诸如Fiddler之类的客户端进行请求时,我得到了整个响应。 但是,我的Windows Phone应用程序仅获取消息数组,而不获取链接对象。 这导致我的序列化程序失败,因为我缺少JSON对象的某些部分。

有谁知道为什么会这样? 如果需要,我可以提供其他代码。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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