Windows Phone 8.1 Google Book REST Api call with HttpClient:

本文关键字:call Api with HttpClient REST Book Phone Google Windows | 更新日期: 2023-09-27 18:01:33

我正在尝试编写一些需要获取有关书籍信息的应用程序。这就是我使用谷歌图书Api的原因。官方库在WP8.1上不工作,所以我试图在互联网的帮助下自己做所有事情。这就是我写的:

 public async Task<RootObject> GetBooks(string query)
    {
        using (HttpClient httpClient = new HttpClient())
        {
            HttpResponseMessage response = new HttpResponseMessage();
            string requestUri = googleApiUri + "q=" + query.Replace(" ", "+") + "&maxResults=10&orderBy=relevance&printType=books&projection=lite";
            string jsonString = "";
            try
            {
                jsonString = await httpClient.GetStringAsync(new Uri(requestUri));
            }
            catch (Exception ex)
            {
                string message = "Error = " + ex.HResult.ToString("X") +
                "  Message: " + ex.Message;
            }
            return ResponseToJson(jsonString);
        }
    }
    private RootObject ResponseToJson(string message)
    {
        return JsonConvert.DeserializeObject<RootObject>(message);
    }

然而,调用httpClient。GetStringAsync抛出我一个错误:"异常从HRESULT: 0x80072EFD"。我不知道为什么会发生这种情况,我在网上找不到任何关于这种例外的信息。我做了什么错误的httpClient?我将非常感谢任何帮助!

提前感谢!

BestRegards,罗马

Windows Phone 8.1 Google Book REST Api call with HttpClient:

你的应用程序有足够的授权吗?通常,在项目的属性中有一个名为WMAppManifest.xml的文件。打开它,转到"Capabilities"选项卡。确保选中了ID_CAP_NETWORKING。这将授权您的应用程序访问互联网。