当前位置:网站首页>C#通用接口调用
C#通用接口调用
2022-07-03 02:58:00 【Mnybgm】
项目场景:
提示:C#通用接口调用
解决方案:
提示:先获取令牌,然后调用数据接口:
/// <summary>
/// 获取Token值
/// </summary>
/// <returns>token值</returns>
public string InterfaceToken()
{
HttpWebRequest request = HttpWebRequest.CreateHttp("http://主机/token?client_id=xxxxxx";);
request.ContentType = "application/json";//body数据类型
request.Method = "GET";
var response = (HttpWebResponse)request.GetResponse();
var resuleJson = string.Empty;//返回的json数据
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
{
resuleJson = reader.ReadToEnd();
}
}
TokenData tokenData = new TokenData();
tokenData = JsonConvert.DeserializeObject<TokenData>(resuleJson);
var aaa= JsonConvert.DeserializeObject(resuleJson);
return tokenData.access_token;
}public class TokenData
{
public string access_token { get; set; }
}调用接口:
/// <summary>
/// 接口数据获取
/// </summary>
/// <param name="citgsOperation">物料组</param>
/// <param name="cpclOperation">分类码</param>
/// <param name="mitm">物料代码</param>
public void InterfaceData(string mitm = "")
{
string citgs = "[]";//citgs 物料组 false
int citgsOperation = 0;//citgsOperation物料组过滤操作 true 0
int cpclOperation = 0;//cpclOperation 分类码过滤操作 true 0
string cpcls = "[]";//cpcls分类码 false
string level = "1";//level需要展开的BOM的层数 false
//string mitm = "";//mitm物料代码 true
string queryDate = "";//queryDate查询时间 false
string token = InterfaceToken();
string data = "{\"citgs\": " + citgs + ",\"citgsOperation\":" + citgsOperation + ",\"cpclOperation\": " + cpclOperation + ",\"cpcls\":" + cpcls + ",\"level\":" + level + ",\"mitm\":\" " + mitm + "\",\"queryDate\": \"" + queryDate + "\"}";
HttpWebRequest request = HttpWebRequest.CreateHttp("http://主机";);
request.ContentType = "application/json";//body数据类型
request.Headers.Add("x-authorization", token);
request.Method = "POST";
using (var postStream = new StreamWriter(request.GetRequestStream()))
{
postStream.Write(data);
}
var response = (HttpWebResponse)request.GetResponse();
var resuleJson = string.Empty;//返回的json数据
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
{
resuleJson = reader.ReadToEnd();
}
}
}边栏推荐
- C language beginner level - pointer explanation - paoding jieniu chapter
- I2C 子系統(四):I2C debug
- 一文带你了解 ZigBee
- The base value is too large (the error is marked as "08") [duplicate] - value too great for base (error token is'08') [duplicate]
- 迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常
- 分布式事务
- Linear rectification function relu and its variants in deep learning activation function
- js根据树结构查找某个节点的下面的所有父节点或者子节点
- Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception
- [shutter] setup of shutter development environment (supplement the latest information | the latest installation tutorial on August 25, 2021)
猜你喜欢

Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 2)

Three. JS local environment setup

A2L file parsing based on CAN bus (2)

What is the way out for children from poor families?

Matlab tips (24) RBF, GRNN, PNN neural network

内存泄漏工具VLD安装及使用

Joking about Domain Driven Design (III) -- Dilemma

random shuffle注意

Build a private cloud disk cloudrev

I2C 子系統(四):I2C debug
随机推荐
The solution of "the required function is not supported" in win10 remote desktop connection is to modify the Registry [easy to understand]
A2L file parsing based on CAN bus (2)
Build a private cloud disk cloudrev
用docker 连接mysql的过程
Getting started | jetpack hilt dependency injection framework
[Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
Force freeing memory in PHP
Add some hard dishes to the interview: how to improve throughput and timeliness in delayed task scenarios!
JMeter performance test JDBC request (query database to obtain database data) use "suggestions collection"
JS finds all the parent nodes or child nodes under a node according to the tree structure
二维格式数组格式索引下标连续问题导致 返回json 格式问题
Are there any recommended term life insurance products? I want to buy a term life insurance.
sql server 查询指定表的表结构
迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常
SQL statement
Informatics Olympiad one general question bank 1006 a+b questions
Andwhere multiple or query ORM conditions in yii2
I2C subsystem (IV): I2C debug
Add MDF database file to SQL Server database, and the error is reported
sql server 查詢指定錶的錶結構