簡體   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