I used a async httpRequest
in this function:
public static async Task<HttpContent> RegisterAysnc(Dictionary<String, String> keyValues)
{
var multForm = new MultipartFormDataContent();
StringBuilder urlParameters = new StringBuilder();
string imgPath = keyValues["avatarSource"];
HttpClient client = new HttpClient();
foreach (var kv in keyValues)
{
if (kv.Key == "avatarSource")
continue;
urlParameters.Append(String.Format("{0}={1}&", kv.Key, kv.Value));
}
FileStream fs = File.OpenRead(imgPath);
multForm.Add(new StreamContent(fs), "photo", Path.GetFileName(imgPath));
var registerURL = URL.registerUrl + urlParameters.ToString();
var response = await client.PostAsync(registerURL, multForm);
return response.Content;
}
and this function is called by another function:
private void RegisterBtn_Click(object sender, RoutedEventArgs e)
{
......
var res = NetWork.RegisterAysnc(parameters);
Console.WriteLine($"Response is: {res.Result}");
}
The server did receive the request from this function, but the Console.WriteLine()
didn't work; I don't know how to receive the sync result of the response.