我有网络服务,我想发送到此网络服务参数值& key,如token =“”和文件
client - >>>>>>>>>>>send>>>>>>>>>web service
token = "exmple"
userfile = sound file
web service (get both) >>>>>>>>send>>>>>> client
result as Json
像邮递员一样:
我在c#中编写此代码,但Web服务无法同时获取令牌和文件。但是没有工作。我错在哪里?意味着数据发送到网络服务。但是服务没有得到令牌和文件。
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();
}