当前位置:网站首页>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();
}
}
}边栏推荐
- MySql实战45讲【行锁】
- Joking about Domain Driven Design (III) -- Dilemma
- Can netstat still play like this?
- [C language] MD5 encryption for account password
- Add automatic model generation function to hade
- Kubernetes family container housekeeper pod online Q & A?
- L'index des paramètres d'erreur est sorti de la plage pour les requêtes floues (1 > Nombre de paramètres, qui est 0)
- I2C 子系统(三):I2C Driver
- Destroy the session and empty the specified attributes
- Concrete CMS vulnerability
猜你喜欢

docker安装redis

Sous - système I2C (IV): débogage I2C

Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
![[principles of multithreading and high concurrency: 1_cpu multi-level cache model]](/img/c7/6b5ab4ff7379bfccff7cdbb358ff8f.jpg)
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]

I2C 子系统(三):I2C Driver

I2C 子系统(一):I2C spec

Didi programmers are despised by relatives: an annual salary of 800000 is not as good as two teachers

一文带你了解 ZigBee

SQL statement

TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
随机推荐
疫情当头,作为Leader如何进行代码版本和需求开发管控?| 社区征文
vfork执行时出现Segmentation fault
leetcode540
Reset or clear NET MemoryStream - Reset or Clear . NET MemoryStream
As a leader, how to control the code version and demand development when the epidemic comes| Community essay solicitation
tensor中的append应该如何实现
Le processus de connexion mysql avec docker
L'index des paramètres d'erreur est sorti de la plage pour les requêtes floues (1 > Nombre de paramètres, qui est 0)
docker安装mysql
Are there any recommended term life insurance products? I want to buy a term life insurance.
MySql实战45讲【SQL查询和更新执行流程】
Deep Reinforcement Learning for Intelligent Transportation Systems: A Survey 论文阅读笔记
I2C 子系统(二):I3C spec
函数栈帧的创建与销毁
敏捷认证(Professional Scrum Master)模拟练习题-2
"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
How to return ordered keys after counter counts the quantity
从输入URL到页面展示这中间发生了什么?
从C到Capable-----利用指针作为函数参数求字符串是否为回文字符
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]