In C # Core, HttpClient () is used instead of WebClient (). I can't figure out how to send the data now. Below is an example using WebClient ():

private void SendMessage(string message, int chatId) { using (var webClient = new WebClient()) { var pars = new System.Collections.Specialized.NameValueCollection(); pars.Add("text", message); pars.Add("chat_id", chatId.ToString()); webClient.UploadValues(Link + "/sendMessage", pars); } } 

    1 answer 1

    Well, something like this:

     using (var httpClient = new HttpClient()) { var dict = new Dictionary<string, string>() { ["text"] = message, ["chat_id"] = chatId.ToString() }; string reply; using (var formContent = new FormUrlEncodedContent(dict)) { using (var response = await httpClient.PostAsync(Link + "/sendMessage", formContent)) { if (response.IsSuccessStatusCode) reply = await response.Content.ReadAsStringAsync(); // иначе произошла ошибка, обрабатываем } } // ... } 

    You will have to use the async method, since the new API is asynchronous.