|
using HttpClient httpClient = new(); string Boundary = new Guid().ToString().Replace("-", ""); var requestContent = new MultipartFormDataContent(Boundary); requestContent.Headers.ContentType = MediaTypeHeaderValue.Parse($"multipart/form-data; boundary={Boundary}"); //传入文件 var fileContent = await File.ReadAllBytesAsync(@"C:\\Users\\XXXX\\Pictures\\123.jpg"); var byteArrayContent = new ByteArrayContent(fileContent); requestContent.Add(byteArrayContent, "file", "123.jpg"); //传入token(字符串格式) System.Net.Http.StringContent stringContent = new(token); requestContent.Add(stringContent, "token"); //发送请求 var postResponse = await httpClient.PostAsync("https://XXXXXploadFile.do", requestContent); //获取请求结果 this.textBox1.Text = await postResponse.Content.ReadAsStringAsync(); |
|