当前位置:网站首页>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();
}
}
}边栏推荐
- Process the dataset and use labelencoder to convert all IDs to start from 0
- Sqlserver row to column pivot
- Can netstat still play like this?
- Update and return document in mongodb - update and return document in mongodb
- A2L file parsing based on CAN bus (2)
- [translation] flux is safe. Gain more confidence through fuzzy processing
- 左值右指解释的比较好的
- 【Flutter】shared_ Preferences local storage (introduction | install the shared_preferences plug-in | use the shared_preferences process)
- JS finds all the parent nodes or child nodes under a node according to the tree structure
- Two dimensional format array format index subscript continuity problem leads to return JSON format problem
猜你喜欢

docker安装redis

Three.js本地环境搭建

random shuffle注意

HW-初始准备

Kubernetes cluster log and efk architecture log scheme

Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception

Random Shuffle attention
![[principles of multithreading and high concurrency: 1_cpu multi-level cache model]](/img/7e/ad9ea78868126b149bd9f15f587e6c.jpg)
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
![[shutter] banner carousel component (shutter_wiper plug-in | swiper component)](/img/a6/5c97ef3f34702b83ebf0511501d757.gif)
[shutter] banner carousel component (shutter_wiper plug-in | swiper component)

Pytest (6) -fixture (Firmware)
随机推荐
Notifydatasetchanged not applicable to recyclerview - notifydatasetchanged not working on recyclerview
Force deduction ----- the minimum path cost in the grid
疫情当头,作为Leader如何进行代码版本和需求开发管控?| 社区征文
JS finds all the parent nodes or child nodes under a node according to the tree structure
Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution
Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling
Left connection, inner connection
Getting started | jetpack hilt dependency injection framework
I2C subsystem (III): I2C driver
Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes
Opengauss database development and debugging tool guide
Kubernetes cluster log and efk architecture log scheme
Apple releases MacOS 11.6.4 update: mainly security fixes
[error record] the parameter 'can't have a value of' null 'because of its type, but the im
Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid
左连接,内连接
Check log4j problems using stain analysis
"Analysis of 43 cases of MATLAB neural network": Chapter 43 efficient programming skills of neural network -- Discussion Based on the characteristics of the new version of MATLAB r2012b
Process the dataset and use labelencoder to convert all IDs to start from 0