Hi all enthusiastics programmers. I am making a get call from a C# client towards a web-api Project The code looks like below
private const string Url = "http://localhost:61809/"; public ItemService() { _httpClient.DefaultRequestHeaders.Accept.Clear(); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); } public async Task<IEnumerable<Item>> GetItemsAsync(string searchString) { List<Items> = null; string path = @"api/item/" + searchString; HttpResponseMessage response = await _httpClient.GetAsync(Url+path).ConfigureAwait(false); if (response.IsSuccessStatusCode) { items = await response.Content.ReadAsAsync<List<Item>>().ConfigureAwait(false); } return items; } Everything works but if a look after a item whcih contains the character # it fails. If i looks for the item i.e Mastering C# it fails. I have debugged this on the backend side also and the content on the backend doesn't contain the character #. The content is Mastering C which of course fails. The same occurs if i sent the request from Postman What can i do to get it works? Some special encoding or configuration of the backend code?
System.Web.HttpUtility.UrlEncode(path)