How can I send a file and form data with the HttpClient?
I have two ways to send a file or form data. But I want to send both like an HTML form. How can I do that? Thanks.
This is my code:
if (openFileDialog1.ShowDialog() == DialogResult.OK) { var client = new HttpClient(); var requestContent = new MultipartFormDataContent(); filename = openFileDialog1.FileName; array = File.ReadAllBytes(filename); var imageContent = new ByteArrayContent(array); imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse("audio/*"); requestContent.Add(imageContent, "audio", "audio.wav"); var values = new Dictionary<string, string> { { "token", "b53b99534a137a71513548091271c44c" }, }; var content = new FormUrlEncodedContent(values); requestContent.Add(content); var response = await client.PostAsync("localhost", requestContent); var responseString = await response.Content.ReadAsStringAsync(); txtbox.Text = responseString.ToString(); }
requestContent).