Beispiel #1
0
        private void button9_Click(object sender, EventArgs e)
        {
            TaskListResult result = new TaskListResult();
            TaskListTest   param  = new TaskListTest();
            string         server = "http://localhost:15988/api/TeamTask/TestLink";

            param.type = "test";
            param.val  = "123654";
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("type", param.type);
            dic.Add("val", param.val);

            try
            {
                HttpWebResponse        response = CreatePostHttpResponse(server, dic, null, null, Encoding.UTF8, null);
                System.IO.StreamReader sr       = new System.IO.StreamReader(response.GetResponseStream());
                string responseContent          = sr.ReadToEnd();
                sr.Close();

                TaskListResult rtn = Deserialize <TaskListResult>(responseContent);

                MessageBox.Show(rtn.val);
            }
            catch (Exception ex)
            {
                return;
            }
        }
        public TaskListResult TestLink([FromBody] TaskListTest param)
        {
            //记时
            LogHelper.Info("TestLink--开始");
            Stopwatch timeWatcher = new Stopwatch();
            long      checkTime   = 0;

            timeWatcher.Restart(); //开始计时
            TaskListResult result = new TaskListResult();

            result.val = "success";
            if (param == null)
            {
                param = new TaskListTest();
                this.Request.GetQueryNameValuePairs();

                HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; //获取传统context
                HttpRequestBase request = context.Request;                                       //定义传统request对象
                param.type = request.Form["type"];
                param.val  = request.Form["val"];

                LogHelper.Info("WebApi-TestLink param from forms");
            }
            try
            {
                result.val = param.val;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                result.val = ex.Message;
                return(result);
            }
            timeWatcher.Stop();//结束计时
            checkTime = timeWatcher.ElapsedMilliseconds;
            LogHelper.Info(string.Format("TestLink--结束,执行时间:{0} ", checkTime));

            return(result);
        }