我正在使用 Windows.Web.Http 而不是 System,我正在尝试发送图像。
我的示例代码:
Dictionary<string, object> requestDictionary;
HttpClient httpClient = new HttpClient();
HttpRequestMessage re = new HttpRequestMessage();
HttpResponseMessage response;
re.Method = HttpMethod.Post;
re.RequestUri = url;
string content_type = "application/json";
string req_data = JsonConvert.SerializeObject(requestDictionary);
re.Content = new HttpStringContent(req_data, UnicodeEncoding.Utf8, content_type);
response = await httpClient.SendRequestAsync(re);
response.EnsureSuccessStatusCode();
var responseString = await response.Content.ReadAsStringAsync();
httpClient.Dispose();
httpClient=null;
在这种情况下,我的 requestDictionary 将类似于
requestDictionary.Add("Image", filename);
requestDictionary.Add("description", some_description);
有人请帮助我实现这一目标。