zoukankan      html  css  js  c++  java
  • 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();
    }
  • 相关阅读:
    Python学习之旅(十二)
    Python学习之旅(十一)
    Python学习之旅(十)
    Python学习之旅(十)
    Python学习之旅(九)
    Python学习之旅(八)
    WPF 画刷应用
    WP8 学习 在APP.XAML中加入Resources
    WP8 学习 ApplicationBar 的创建 XAML代码
    WP8 学习 Onnavigatedto和OnnavigatedFrom的区别
  • 原文地址:https://www.cnblogs.com/sdya233/p/14704803.html
Copyright © 2011-2022 走看看