public static async Task <JToken> GetAlbumAsync(int id) { FormUrlEncodedCollection parameters; parameters = new FormUrlEncodedCollection { { "id", id.ToString() } }; using (HttpClient client = new HttpClient()) using (HttpResponseMessage response = await client.SendAsync(HttpMethod.Get, ALBUM_URL, parameters, null)) { JObject json; json = JObject.Parse(await response.Content.ReadAsStringAsync()); if ((int)json["code"] != 200) { throw new HttpRequestException(); } return(json); } }
public static async Task <JToken> SearchAsync(IEnumerable <string> keywords, SearchType type, int limit) { FormUrlEncodedCollection parameters; parameters = new FormUrlEncodedCollection { { "s", string.Join(" ", keywords) }, { "type", ((int)type).ToString() }, { "limit", limit.ToString() } }; using (HttpClient client = new HttpClient()) using (HttpResponseMessage response = await client.SendAsync(HttpMethod.Get, SEARCH_URL, parameters, null)) { JObject json; json = JObject.Parse(await response.Content.ReadAsStringAsync()); if ((int)json["code"] != 200) { throw new HttpRequestException(); } return(json["result"]); } }