.net网络请求

var httpClient = new HttpClient(); //实例化一个请求对象
httpClient.DefaultRequestHeaders.Add("Authorization", "123456");//添加请求头的相关内容
HttpContent content = new StringContent(JsonConvert.SerializeObject(parameters), Encoding.UTF8, "application/json");//设置请求体(请求内容,编码,格式)
var response = await httpClient.PostAsync("http://localhost:36123/api/demo/Test/upload", content);//发起请求
var msg = "";
if (response.StatusCode==HttpStatusCode.OK) {
msg= await response.Content.ReadAsStringAsync();//读取响应的内容
}

posted @ 2022-11-14 10:11  Agreoself  阅读(73)  评论(0编辑  收藏  举报