ABP 后台调用接口 获取返回的数据

Posted guxingy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABP 后台调用接口 获取返回的数据相关的知识,希望对你有一定的参考价值。

原文:https://www.cnblogs.com/i3yuan/p/10703500.html

 

 

insert 简单测试:

 

技术图片

 

 

        public void test8()
        {
            string url = "http://localhost:21021/api/services/app/Role/Create";

            var str2 = HttpPost3(url, System.IO.File.ReadAllText("2.txt"));
            Console.WriteLine(str2);
            Console.Read();
        }

 

        public string HttpPost4(string url, string body)
        {
            Encoding encoding = Encoding.UTF8;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/json-patch+json";          
            byte[] buffer = encoding.GetBytes(body);
            request.ContentLength = buffer.Length;
            request.GetRequestStream().Write(buffer, 0, buffer.Length);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
            {
                return reader.ReadToEnd();
            }
        }

 

 

 

 

update简单测试:

 

        public void test10()
        {
            string url = "http://localhost:21021/api/services/app/Menu/Update";
            var str2 = HttpPost5(url, "{"name": "1","url": "1","id": "1"}");
            Console.WriteLine(str2);
            Console.Read();
        }

 

        public string HttpPost5(string url, string body)
        {
            Encoding encoding = Encoding.UTF8;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "PUT";
            request.ContentType = "application/json-patch+json";
            byte[] buffer = encoding.GetBytes(body);
            request.ContentLength = buffer.Length;
            request.GetRequestStream().Write(buffer, 0, buffer.Length);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
            {
                return reader.ReadToEnd();
            }
        }

 

 

delete简单测试:

        public void test11()
        {
            string url = "http://localhost:21021/api/services/app/Menu/Delete?Id=12";
            var str2 = Delete("", url);
            Console.WriteLine(str2);
            Console.Read();
        }

 

        public string Delete(string data, string uri)
        {
            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(uri);
            byte[] buf = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(data);
            Request.Method = "DELETE";
            Request.ContentLength = buf.Length;
            Request.ContentType = "application/json";
            Request.MaximumAutomaticRedirections = 1;
            Request.AllowAutoRedirect = true;
            Stream stream = Request.GetRequestStream();
            stream.Write(buf, 0, buf.Length);
            stream.Close();
            HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
            StreamReader reader = new StreamReader(Response.GetResponseStream(), Encoding.UTF8);
            string returnXml = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
            reader.Close();
            Response.Close();
            return returnXml;
        }

 

以上是关于ABP 后台调用接口 获取返回的数据的主要内容,如果未能解决你的问题,请参考以下文章

ABP官方文档翻译 3.3 仓储

java后台接口怎么方便返回restful数据

thinkjs学习-this.assign传递数据和ajax调用后台接口

ABP开发框架前后端开发系列---ABP基础接口处理和省份城市行政区管理模块的开发

使用$.ajax调用接口,返回登录页面,所以我想先用ajax将用户名密码传给登录接口。返回成功但没有记住登录

ABP js调用后台的删除 参数为int类型 非对象