当前位置:网站首页>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();
}
}
}边栏推荐
- Variable declarations following if statements
- js根据树结构查找某个节点的下面的所有父节点或者子节点
- 力扣------网格中的最小路径代价
- Can netstat still play like this?
- Baidu map - surrounding search
- HTB-Devel
- Are there any recommended term life insurance products? I want to buy a term life insurance.
- Andwhere multiple or query ORM conditions in yii2
- tensor中的append应该如何实现
- 迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常
猜你喜欢

I2C subsystem (II): I3C spec

Creation and destruction of function stack frame

SqlServer行转列PIVOT

I2C 子系统(三):I2C Driver
![[flutter] example of asynchronous programming code between future and futurebuilder (futurebuilder constructor setting | handling flutter Chinese garbled | complete code example)](/img/04/88ce45d370a2e6052c2fce558aa531.jpg)
[flutter] example of asynchronous programming code between future and futurebuilder (futurebuilder constructor setting | handling flutter Chinese garbled | complete code example)

The Linux server needs to install the agent software EPS (agent) database

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

Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes

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

Add automatic model generation function to hade
随机推荐
Can I use read-only to automatically implement properties- Is read-only auto-implemented property possible?
Today, it's time to copy the bottom!
Yiwen takes you to know ZigBee
处理数据集,使用LabelEncoder将所有id转换为从0开始
Docker install redis
Use of check boxes: select all, deselect all, and select some
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
Andwhere multiple or query ORM conditions in yii2
JMeter performance test JDBC request (query database to obtain database data) use "suggestions collection"
Use optimization | points that can be optimized in recyclerview
HW initial preparation
SQL Server Query spécifie la structure de la table
C语言初阶-指针详解-庖丁解牛篇
[C language] MD5 encryption for account password
Change cell color in Excel using C - cell color changing in Excel using C
As a leader, how to control the code version and demand development when the epidemic comes| Community essay solicitation
Joking about Domain Driven Design (III) -- Dilemma
Why choose a frame? What frame to choose
Kubernetes cluster log and efk architecture log scheme
The process of connecting MySQL with docker