ABP background call interface to obtain data returned

Original: https: //www.cnblogs.com/i3yuan/p/10703500.html

 

 

insert a simple test:

 

 

 

        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 a simple test:

 

        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();
            }
        }

 

Guess you like

Origin www.cnblogs.com/guxingy/p/11972121.html