1

I have web service and i want to send to this web service parameter value&key like token = "" and file

client - >>>>>>>>>>>send>>>>>>>>>web service
token = "exmple"
userfile = sound file

web service (get both) >>>>>>>>send>>>>>> client
result as Json

like as Postman : enter image description here

i write this code in c# but web service cannot get both token and file. but not working.Where I was wrong?means data send to web service.but service not get token and file.

        byte[] array;
        string filename;
        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", "111fhgbbrvjndskbsd" },
            };
            var content = new FormUrlEncodedContent(values);
            requestContent.Add(content);
            var response = await client.PostAsync("example.com/upload", requestContent);
            var responseString = await response.Content.ReadAsStringAsync();
            txtbox.Text = responseString.ToString();
        }
user2254798
  • 553
  • 2
  • 6
  • 17

0 Answers0