当前位置:网站首页>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();
}
}
}
边栏推荐
- sql server数据库添加 mdf数据库文件,遇到的报错
- Do you really understand relays?
- 从输入URL到页面展示这中间发生了什么?
- 左连接,内连接
- Check log4j problems using stain analysis
- What is the way out for children from poor families?
- Serious security vulnerabilities reported by moxa mxview network management software
- leetcode540
- open file in 'w' mode: IOError: [Errno 2] No such file or directory
- C语言中左值和右值的区别
猜你喜欢
HW initial preparation
Opengauss database development and debugging tool guide
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
What is the way out for children from poor families?
Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes
Left connection, inner connection
Kubernetes cluster log and efk architecture log scheme
Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception
Classes and objects - initialization and cleanup of objects - constructor call rules
随机推荐
docker安装redis
Update and return document in mongodb - update and return document in mongodb
从C到Capable-----利用指针作为函数参数求字符串是否为回文字符
Serious security vulnerabilities reported by moxa mxview network management software
Linear rectification function relu and its variants in deep learning activation function
左值右指解释的比较好的
敏捷认证(Professional Scrum Master)模拟练习题
From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character
sql server数据库添加 mdf数据库文件,遇到的报错
Installation and use of memory leak tool VLD
I2C 子系统(四):I2C debug
How to select the minimum and maximum values of columns in the data table- How to select min and max values of a column in a datatable?
用docker 連接mysql的過程
"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
Practice of traffic recording and playback in vivo
yii2 中andWhere多个or查询 orm条件
Use cve-2021-43893 to delete files on the domain controller
open file in 'w' mode: IOError: [Errno 2] No such file or directory
How to use asp Net MVC identity 2 change password authentication- How To Change Password Validation in ASP. Net MVC Identity 2?
How to implement append in tensor