欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#中API调用的多种方法

程序员文章站 2022-06-15 18:38:42
介绍 api( application programming interface ),我想大家不会陌生,它是我们windows编程的常客,虽然基于.net平台的c#有了强大的类库,但是,我们还是不能...

介绍

api( application programming interface ),我想大家不会陌生,它是我们windows编程的常客,虽然基于.net平台的c#有了强大的类库,但是,我们还是不能否认api在windows编程中的重要性.大多数的编程语言都支持api编程,而.net平台中的mfc(microsoft foundation class library)构架本身就封装了大部分的api.

    做为程序员,我们需要了解api从字面上了解便是编程接口,因此,做为开发者,需要了解的只是api的使用方法.

api根据操作系统、处理器及功能性的不同而拥有很多不同的类型.     操作系统特用的api:

    每种操作系统都有许多通用的api以及一些特用的api,这些特用的api只能在当前操作系统中执行.

方式1

 //通过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();
            }
        }

方式2

/// 执行 存储过程
                /// 返回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", "20210605141700254036@004.078.0050010@119414@@21231@20210605@9000");

                string codemsg = utility.executeprocedure(jobj.tostring());
                system.diagnostics.debug.writeline(codemsg);

引用api dll

C#中API调用的多种方法

到此这篇关于c#中api调用的多种方法的文章就介绍到这了,更多相关c#调用api内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

相关标签: c# API