1.HttpClient方式
HttpClient webClient = new HttpClient(); webClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken); var formdata = new MultipartFormDataContent { { new StringContent(originalFileName), "fileRelativePath" }, { new StringContent(fileName),"fileGuidPath"}, { new StringContent(userid.ToString()),"userid" } }; await webClient.PostAsync($"{_configuration.GetSection("OAServerAddress").Value}/api/services/AppApi/Customers/EditHead", formdata);
2.WebClient方式
var requst_sour = new Dictionary<string, object> { { "usernameOrEmailAddress", "admin" }, { "Password", "123qwe" } }; var requst_sourStr = Encoding.UTF8.GetBytes(requst_sour.ToJsonString()); var webClient = new WebClient(); webClient.Headers.Add("Content-Type", "application/json"); var reponseByte= webClient.UploadData($"{_configuration.GetSection("OAServerAddress").Value}/api/TokenAuth/Authenticate ", "POST", requst_sourStr); var bearerToken = Encoding.UTF8.GetString(reponseByte); var token = JsonConvert.DeserializeObject<dynamic>(bearerToken); return token.result.accessToken;