介绍
API( Application Programming Interface ),我想大家不会陌生,它是我们Windows编程的常客,虽然基于.Net平台的C#有了强大的类库,但是,我们还是不能否认API在Windows编程中的重要性.大多数的编程语言都支持API编程,而.Net平台中的MFC(Microsoft Foundation Class Library)构架本身就封装了大部分的API.
做为程序员,我们需要了解API从字面上了解便是编程接口,因此,做为开发者,需要了解的只是API的使用方法.
API根据操作系统、处理器及功能性的不同而拥有很多不同的类型.操作系统特用的API:每种操作系统都有许多通用的API以及一些特用的API,这些特用的API只能在当前操作系统中执行.
点击获取测试key和secret
方式一:
//通过API进行解析扫入的二维码
string CodeMsg = HttpPost("http://eap2mes:8088/App/ExecuteProcedure?", "EventType=APP_REELIDSPLIT&InputJson=" + "{CODE:\"" + newCodeText + "\"}");
System.Diagnostics.Debug.WriteLine(CodeMsg);
public static string HttpPost(string url, string body)
{
Encoding encoding = Encoding.UTF8;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.Accept = "text/html, application/xhtml+xml, */*";
request.ContentType = "application/x-www-form-urlencoded";
byte[] buffer = encoding.GetBytes(body);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
方式二:
/// 执行 存储过程
/// 返回Json字符串 { "Result": "OK", "Msg": "", "Return_Data": "" } OR { "Result": "NG", "Msg": "Error Msg", "Return_Data": "" }
/// Return_Data : 依存储过程而定,可以是独立基础型字符串,也可以是Json格式字符串
JObject JObj = new JObject();
JObj.Add("FunctionID", "REELID-SPLIT");
JObj.Add("CODE", "[email protected]@119414@@21231@20210605@9000");
string CodeMsg = Utility.ExecuteProcedure(JObj.ToString());
System.Diagnostics.Debug.WriteLine(CodeMsg);