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

原文地址:https://www.cnblogs.com/guxingy/p/11972121.html

时间: 2024-08-08 08:59:29

ABP 后台调用接口 获取返回的数据的相关文章

二级联动:map,for循环一级数据,调用接口获取对象数据依次放到数组里(解决由于后端java是多线程,接收到的数据放入(push)数组中有可能会顺序不对)

解决方法:遍历一级数据时先push一个新的对象,调用接口获取到数据之后splice方法通过index的值判断放入到数组的对应下标下 this.tableData一级数据:  this.relationMaterialNameList二级数据: this.tableData.map((item,index)=>{ this.relationMaterialNameList.push({}) // 编辑页面项目下拉框数据 this.getSpecificationList(item.reimburs

coco2dx jni 调用 java 相机返回 图片数据

新建 一个项目 名字:testJin  包名:com.TanSon.org  python命令:python create_project.py -project testJin -package com.TanSon.org -language cpp eclipse 导入项目配置 ... 略去,(可以google) 1 c++ 调用 andriod 1.1 包含头文件 #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include <jni.

(截选)调用.app获取 返回的结果

模块/app/ 测试点 条件 期望结果 /.../login 登陆后初始化数据 post,true document.getElementById的表格 /.../loginout post,false 玩家属性 /.../load_attribute 显示数据(GUI)ok Get,false /.../load_attribute 显示数据in/out Get,false /.../load_attribute 显示数据的load顺序 Get,false coupon --道具货币的模式 f

如何在后台调用接口

string url = "http://localhost:12083/api/common/GetVerifyCode"; string strType = "application/x-www-form-urlencoded"; string strPar = "userName=18382565651";//拼接参数 HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Cr

使用httpClient调用接口获取响应数据

转自:https://blog.csdn.net/shuaishuaidewo/article/details/81136088 import lombok.extern.slf4j.Slf4j; import okhttp3.*; /** * 需要注入依赖 * <dependency> * <groupId>com.squareup.okhttp3</groupId> * <artifactId>okhttp</artifactId> * &l

微信小程序前端调用后台方法并获取返回值

wxml代码 <wxs src="../../wxs/string.wxs" module="tools" /> <!-- 调用tools.img(item.content)返回bool,也可以返回其他值 --> <view class='clearfix' wx:if="{{tools.img(item.content)}}"> <view class='content-view'> <im

JAVA调用接口获取数据

package com.zving.zzfw.bl; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; import com.zving.appapi.util.HttpClientUtil; import com.zving.framework.json.JSONObject; /** * @author Clover * 登录用户同

java调用shell获取返回值

转自:http://blog.csdn.net/tengdazhang770960436/article/details/12014839 1.shell文件return.sh echo 1 echo 2 echo 3 2.java文件Test.java [java] view plain copy import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.InputStreamReader

jQuery调用ajax获取json格式数据

<body> <div>点击按钮获取音乐列表</div> <input type="button" id="button" value="确定" /> <div id="result"></div> <div>添加新的音乐</div> <input type="text" name=""