async void GoLibraryListPageAsync(String prefecture, String city) { try { CalilCredentials calilKey = LoadCredentialsFile(); string url = "http://api.calil.jp/library?appkey=" + calilKey.api_key + "&pref=" + System.Net.WebUtility.UrlEncode(prefecture) + "&city=" + System.Net.WebUtility.UrlEncode(city) + "&format=json&callback= "; WebRequest request = WebRequest.Create(url); WebResponse response = await request.GetResponseAsync(); Stream st = response.GetResponseStream(); StreamReader sr = new StreamReader(st); string responseFromServer = sr.ReadToEnd(); System.Diagnostics.Debug.WriteLine(responseFromServer.ToString()); await Navigation.PushAsync(new SelectLibraryPage(calilKey.api_key, prefecture, city, responseFromServer)); } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.ToString()); } }
public static CalilCredentials LoadCredentialsFile() { //CalilCredentials.json sample //{"api_key":"XXXXX"} var assembly = typeof(SelectCityPage).GetTypeInfo().Assembly; Stream stream = assembly.GetManifestResourceStream("MyBookReading.Assets.CalilCredentials.json"); string text = ""; using (var reader = new System.IO.StreamReader(stream)) { text = reader.ReadToEnd(); } CalilCredentials key = JsonConvert.DeserializeObject <CalilCredentials>(text); return(key); }