当前位置:网站首页>C # general interface call
C # general interface call
2022-07-03 03:01:00 【Mnybgm】
Project scenario :
Tips :C# General interface call
Solution :
Tips : Get token first , Then call the data interface :
/// <summary>
/// obtain Token value
/// </summary>
/// <returns>token value </returns>
public string InterfaceToken()
{
HttpWebRequest request = HttpWebRequest.CreateHttp("http:// host /token?client_id=xxxxxx";);
request.ContentType = "application/json";//body data type
request.Method = "GET";
var response = (HttpWebResponse)request.GetResponse();
var resuleJson = string.Empty;// Back to json data
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; }
}Call interface :
/// <summary>
/// Interface data acquisition
/// </summary>
/// <param name="citgsOperation"> Item group </param>
/// <param name="cpclOperation"> Category code </param>
/// <param name="mitm"> Material code </param>
public void InterfaceData(string mitm = "")
{
string citgs = "[]";//citgs Item group false
int citgsOperation = 0;//citgsOperation Material group filtering true 0
int cpclOperation = 0;//cpclOperation Classification code filtering true 0
string cpcls = "[]";//cpcls Category code false
string level = "1";//level Need to expand BOM The number of layers false
//string mitm = "";//mitm Material code true
string queryDate = "";//queryDate Query time 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:// host ";);
request.ContentType = "application/json";//body data type
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;// Back to json data
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
{
resuleJson = reader.ReadToEnd();
}
}
}边栏推荐
- Serious security vulnerabilities reported by moxa mxview network management software
- 用docker 連接mysql的過程
- Unity3d human skin real time rendering real simulated human skin real time rendering "suggestions collection"
- docker安装redis
- Creation and destruction of function stack frame
- Chart. JS multitooltip tag - chart js multiTooltip labels
- Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 2)
- Kubernetes cluster log and efk architecture log scheme
- SQL server queries the table structure of the specified table
- Baidu map - surrounding search
猜你喜欢

Kubernetes cluster log and efk architecture log scheme

Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
![[error record] the parameter 'can't have a value of' null 'because of its type, but the im](/img/1c/46d951e2d0193999f35f14d18a2de0.jpg)
[error record] the parameter 'can't have a value of' null 'because of its type, but the im

超好用的日志库 logzero

A2L file parsing based on CAN bus (2)

Docker install redis

左连接,内连接

HW initial preparation

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

vfork执行时出现Segmentation fault
随机推荐
力扣------网格中的最小路径代价
What is the way out for children from poor families?
The solution of "the required function is not supported" in win10 remote desktop connection is to modify the Registry [easy to understand]
I2C 子系统(四):I2C debug
Reset or clear NET MemoryStream - Reset or Clear . NET MemoryStream
TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
The Linux server needs to install the agent software EPS (agent) database
处理数据集,使用LabelEncoder将所有id转换为从0开始
Unity3d human skin real time rendering real simulated human skin real time rendering "suggestions collection"
后管中编辑与预览获取表单的值写法
Add automatic model generation function to hade
Baidu map - surrounding search
I2C 子系统(三):I2C Driver
The core idea of performance optimization, dry goods sharing
Kubernetes cluster log and efk architecture log scheme
Super easy to use logzero
Are there any recommended term life insurance products? I want to buy a term life insurance.
Practice of traffic recording and playback in vivo
[error record] the parameter 'can't have a value of' null 'because of its type, but the im
Counter统计数量后,如何返回有序的key