.Net Get 后台请求网络接口

1、建立网络请求方法

 public static string GetClass(string teacherid, string classdate)
        {
         string url = "http://apiidt.onesmart.org:852/apphandler.ashx?act=GetClass&teacherid=" + teacherid + "&classdate=" + classdate;//请求地址 + 参数拼接
            int Timeout = 5000;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "GET";
            request.ContentType = "text/html;charset=UTF-8";
            request.UserAgent = null;
            request.Timeout = Timeout;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
            return retString;
        }

2、调用请求方法

 public JsonResult Post() {         
            string result = getAllClass("2E47571E-B418-44B0-9942-B15A8BF2E03D",7);//填写方法所需的参数

            return Json(result,JsonRequestBehavior.AllowGet);
        }

3、效果展示

.Net Get 后台请求网络接口_第1张图片

你可能感兴趣的:(.Net Get 后台请求网络接口)