当前位置:网站首页>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();
}
}
}边栏推荐
- Distributed transaction
- 用docker 连接mysql的过程
- Pytest (6) -fixture (Firmware)
- sql server 查询指定表的表结构
- [shutter] setup of shutter development environment (supplement the latest information | the latest installation tutorial on August 25, 2021)
- I2C 子系统(一):I2C spec
- 从C到Capable-----利用指针作为函数参数求字符串是否为回文字符
- I2C subsystem (III): I2C driver
- Three. JS local environment setup
- Use optimization | points that can be optimized in recyclerview
猜你喜欢

Summary of interview project technology stack

Pytest (6) -fixture (Firmware)

I2C subsystem (I): I2C spec

C language beginner level - pointer explanation - paoding jieniu chapter

What does "where 1=1" mean

Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)

函数栈帧的创建与销毁

内存泄漏工具VLD安装及使用
![[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]

Deep Reinforcement Learning for Intelligent Transportation Systems: A Survey 论文阅读笔记
随机推荐
Distributed transaction
C语言初阶-指针详解-庖丁解牛篇
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
超好用的日志库 logzero
Sqlserver row to column pivot
random shuffle注意
I2C subsystem (III): I2C driver
Two dimensional format array format index subscript continuity problem leads to return JSON format problem
How to limit the size of the dictionary- How to limit the size of a dictionary?
销毁Session和清空指定的属性
[fluent] futurebuilder asynchronous programming (futurebuilder construction method | asyncsnapshot asynchronous calculation)
JS finds all the parent nodes or child nodes under a node according to the tree structure
Do you really understand relays?
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?
What is the way out for children from poor families?
"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
用docker 连接mysql的过程
open file in 'w' mode: IOError: [Errno 2] No such file or directory
Change cell color in Excel using C - cell color changing in Excel using C