.NET 后台请求API

public static ResponseParam SendByHttpClienttoApi_LoginOn(string name, string password)
        {
            RequestParam para = new RequestParam()
            {
                APPID = appid,
                APPSecret = appsecrect,
                MemberName = name,
                Password = password,
                IPAddress = WebHelper.GetClientIP()
            };
            using (var httpClient = new HttpClient())
            {
                string jsonString = JsonConvert.SerializeObject(para);
                byte[] bytes = Encoding.UTF8.GetBytes(jsonString);
                using (StreamContent httpContent = new StreamContent(new MemoryStream(bytes)))
                {
                    httpContent.Headers.ContentLength = bytes.Length;
                    httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                    var result = httpClient.PostAsync("http://hisapi.customskb.com/api/Member/LoginNew", httpContent).Result.Content.ReadAsStringAsync().Result;
                    ResponseParam objectResult = JsonConvert.DeserializeObject<ResponseParam>(result);
                    return objectResult;
                }

            }
        }

  

原文地址:https://www.cnblogs.com/caolingyi/p/8548127.html