当前位置:网站首页>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();
}
}
}边栏推荐
- [Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
- I2C 子系統(四):I2C debug
- Source code analysis | resource loading resources
- 2022-2028 global splicing display industry research and trend analysis report
- Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
- How to implement append in tensor
- leetcode540
- I2C subsystem (IV): I2C debug
- Check log4j problems using stain analysis
- Build a private cloud disk cloudrev
猜你喜欢

Summary of interview project technology stack

Installation and use of memory leak tool VLD

力扣------网格中的最小路径代价

从C到Capable-----利用指针作为函数参数求字符串是否为回文字符

Practice of traffic recording and playback in vivo

I2C subsystem (III): I2C driver

I2C subsystem (II): I3C spec

I2C subsystem (IV): I2C debug

Do you really understand relays?

Build a private cloud disk cloudrev
随机推荐
How to implement append in tensor
一文带你了解 ZigBee
Practice of traffic recording and playback in vivo
Cancer biopsy instruments and kits - market status and future development trends
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
Serious security vulnerabilities reported by moxa mxview network management software
Global and Chinese ammonium dimolybdate market in-depth analysis and prospect risk prediction report 2022 Edition
销毁Session和清空指定的属性
【富瀚6630编码存录像,用rtsp服务器及时间戳同步实现vlc观看录像】
Kubernetes cluster log and efk architecture log scheme
I2C 子系统(一):I2C spec
vfork执行时出现Segmentation fault
How to use asp Net MVC identity 2 change password authentication- How To Change Password Validation in ASP. Net MVC Identity 2?
Update and return document in mongodb - update and return document in mongodb
Pytest (6) -fixture (Firmware)
C语言中左值和右值的区别
Counter统计数量后,如何返回有序的key
open file in 'w' mode: IOError: [Errno 2] No such file or directory
处理数据集,使用LabelEncoder将所有id转换为从0开始
Creation and destruction of function stack frame