已有140人关注
C# winform 如何调用webapi接口数据
发表在C#答疑区 2022-07-18 悬赏:20 学分
是否精华
版块置顶:

C/S客户端的Winform窗体直接调用WebApi接口,我使用的C#版本是2019,具体需求如下:

API接口规范: https://www.apifox.cn/apidoc/shared-eecd1f10-bb24-4d1c-9f23-880401344fea 

访问密码: CJVXqtLQ

调用方法:

1、先 post {"username":"admin","password":"test123+"} 到 https://api-dev.vlauncher.com/jeecg-boot/apis/login 获取令牌

2、再 post {"isPage":false} 到 https://api-dev.vlauncher.com/jeecg-boot/apis/dwCustomer/listToForeign 获取全部客户数据,header加上"X-Access-Token=获取到的令牌"

返回数据格式:

{

    "success": true,

    "message": "",

    "code": 200,

    "result": {

        "pageNo": null,

        "pageSize": null,

        "records": [

            {

                "custId": "1039778",

                "custCode": "K003",

                "custName": "金寶電子(中國)有限公司",

                "custShortName": "金寶電子",

                "activeStatus": "启用",

                "approvalStatus": "已审核",

                "salesCode": "SALES06",

                "salesName": "唐萍",

                "salesDept": "ZC业务部",

                "salesTeam": "业务1组,业务主管组",

                "engCode": null,

                "engName": null,

                "engDept": null,

                "engTeam": null,

                "industry": null,

                "companyType": null,

                "regCapital": null,

                "shareholder": null,

                "founded": null,

                "companySize": null,

                "bizLicense": null,

                "costStrategyName": null,

                "contact": "戴曉青",

                "phone1": "156-9769-2262",

                "phone2": "轉分機:13064",

                "fax": "",

                "email": "xiaoqing_dai@kinpo.com.cn",

                "region": null,

                "country": null,

                "province": null,

                "addr1": "廣東省東莞市長安鎮沙頭南區  振安路417號 交电通厂,找周思顺",

                "addr2": "廣東省東莞市長安鎮沙頭南區  振安路417號",

                "currencyName": "人民币",

                "discountRate": 1,

                "taxFlag": "0",

                "taxRate": 0.17,

                "shippingMethodName": "By truck",

                "paymentTermName": "月结90天付款",

                "customerLevel": null,

                "customerType": null,

                "firstRfqDate": null,

                "lastRfqDate": null,

我按照网上的方法试过,但是没有成功,请大侠们帮忙解决,也可以私聊。

分享到:
精彩评论 3
game99258
学分:2266 LV10
2022-07-19
沙发

代码没完全吧?

小禾斗
学分:7303 LV13
TA的每日心情
奋斗
2017-04-21 14:00:25
2022-07-19
板凳

你给的这个地址,有各个语言的示例代码啊

var client = new RestClient("https://api.vlauncher.com/jeecg-boot/apis//listToForeign");

client.Timeout = -1;

var request = new RestRequest(Method.POST);

request.AddHeader("X-Access-Token", "");

client.UserAgent = "apifox/1.0.0 (https://www.apifox.cn)";

request.AddHeader("Content-Type", "application/json");

var body = @"";

request.AddParameter("application/json", body,  ParameterType.RequestBody);

IRestResponse response = client.Execute(request);

Console.WriteLine(response.Content);

18823058375
学分:30 LV2
2022-07-19
地板

小禾斗 发表于2022-07-19 14:39

你给的这个地址,有各个语言的示例代码啊

var client = new RestClient("https://api.vlauncher.com/jeecg-boot/apis//listToForeign");

client.Timeout = -1;

var request = new RestRequest(Method.POST);

request.AddHeader("X-Access-Token", "");

client.UserAgent = "apifox/1.0.0 (https://www.apifox.cn)";

request.AddHeader("Content-Type", "application/json");

var body = @"";

request.AddParameter("application/json", body,  ParameterType.RequestBody);

IRestResponse response = client.Execute(request);

Console.WriteLine(response.Content);

是的,今天已解决的差不多了,谢谢!


另外我想了解了解一下,如何快速的把response.Content的数据记录取出来。

首页上一页 1 下一页尾页 3 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照