C# 后台访问接口
string idcard = this.labIdcard.Text.ToString(); string url = ConfigurationManager.AppSettings["apiIp"].ToString(); string action = "/api/action?" + idcard; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url + action); webRequest.ContentType = "text/json;charset=\"utf-8\""; webRequest.Accept = "text/json"; webRequest.Method = "get"; var httpResponse = (HttpWebResponse)webRequest.GetResponse(); var streamReader = new StreamReader(httpResponse.GetResponseStream()); var result = streamReader.ReadToEnd(); JObject jo = (JObject)JsonConvert.DeserializeObject(result); string code = jo["code"].ToString(); if (code == "200") { BindList(); } string idcard = this.labIdcard.Text.ToString(); string url = ConfigurationManager.AppSettings["apiIp"].ToString(); string action = "/api/action?" + idcard; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url + action); webRequest.ContentType = "text/json;charset=\"utf-8\""; webRequest.Accept = "text/json"; webRequest.Method = "post"; string json = new JavaScriptSerializer().Serialize(new { secret = secret, szdw = szdw }); //传参 byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes(json); Stream requestStream = webRequest.GetRequestStream(); requestStream.Write(buffer, 0, buffer.Length); requestStream.Close(); var httpResponse = (HttpWebResponse)webRequest.GetResponse(); var streamReader = new StreamReader(httpResponse.GetResponseStream()); var result = streamReader.ReadToEnd(); JObject jo = (JObject)JsonConvert.DeserializeObject(result); string code = jo["code"].ToString(); if (code == "200") { BindList(); }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步