当前位置:网站首页>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();
}
}
}
边栏推荐
- TCP handshake three times and wave four times. Why does TCP need handshake three times and wave four times? TCP connection establishes a failure processing mechanism
- 左值右指解释的比较好的
- How to use asp Net MVC identity 2 change password authentication- How To Change Password Validation in ASP. Net MVC Identity 2?
- ComponentScan和ComponentScans的区别
- sql server数据库添加 mdf数据库文件,遇到的报错
- Are there any recommended term life insurance products? I want to buy a term life insurance.
- Parameter index out of range (1 > number of parameters, which is 0)
- A2L file parsing based on CAN bus (2)
- MySql实战45讲【行锁】
- Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception
猜你喜欢
Random shuffle note
Le processus de connexion mysql avec docker
一文带你了解 ZigBee
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
Didi programmers are despised by relatives: an annual salary of 800000 is not as good as two teachers
MySql实战45讲【全局锁和表锁】
Check log4j problems using stain analysis
Check log4j problems using stain analysis
Can netstat still play like this?
C language beginner level - pointer explanation - paoding jieniu chapter
随机推荐
C#通用接口调用
sql server数据库添加 mdf数据库文件,遇到的报错
docker安装mysql
力扣------网格中的最小路径代价
Check log4j problems using stain analysis
How to implement append in tensor
复选框的使用:全选,全不选,选一部分
SQL statement
sql server 查詢指定錶的錶結構
疫情当头,作为Leader如何进行代码版本和需求开发管控?| 社区征文
2022-2028 global splicing display industry research and trend analysis report
HTB-Devel
Add automatic model generation function to hade
Kubernetes family container housekeeper pod online Q & A?
TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
Use cve-2021-43893 to delete files on the domain controller
The process of connecting MySQL with docker
Didi programmers are despised by relatives: an annual salary of 800000 is not as good as two teachers
SqlServer行转列PIVOT
Yiwen takes you to know ZigBee