private async void OnSearchPressed(object sender, EventArgs e) { SearchBar searchBar = (SearchBar)sender; EbaySearch search = new EbaySearch(searchBar.Text); string json = JsonConvert.SerializeObject(search); HttpResponseMessage response = await GetProduct.GetProducts(json); if (response.IsSuccessStatusCode) { string response_content = await response.Content.ReadAsStringAsync(); Products = JsonConvert.DeserializeObject <List <Product> >(response_content); MyCollectionView.ItemsSource = Products; } else { if (response.StatusCode == System.Net.HttpStatusCode.BadGateway) { await DisplayAlert("Try Again!", "No connection with the server", "OK"); } if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { await DisplayAlert("Try Again!", "Invalid request", "OK"); } } }