《eoLinker-API_Shop_虚拟货币大全_API接口_C#调用示例代码》由会员分享,可在线阅读,更多相关《eoLinker-API_Shop_虚拟货币大全_API接口_C#调用示例代码(9页珍藏版)》请在金锄头文库上搜索。
1、eoLinker-API Shop 虚虚拟货币拟货币大全大全 C#调调用示例代用示例代码码虚虚拟货币拟货币大全大全涵盖比特币、以太坊等热门虚拟货币与最新发行的虚拟货币,包括币种名称、市值 、24小时交易量、货币总量等信息,实时更新,该产该产品品拥拥有以下有以下APIs: :1.获取虚拟币种列表2.搜索虚拟币3.查询虚拟币详情注意,注意,该该示例代示例代码仅码仅适用于适用于 网站下网站下API 使用使用该产该产品前,您需要通品前,您需要通过过 https:/ 申申请请API服服务务1.获获取虚取虚拟币拟币种列表种列表 using System; using System.Collections
2、.Generic; using System.IO; using System.Net; using System.Text; using System.Web.Script.Serialization;namespace apishop_sdk class Program/* 转发请求到目的主机* param method string 请求方法* param url string 请求地址* param params Dictionary 请求参数* param headers Dictionary 请求头* return string*/static string apishop_sen
3、d_request(string method, string url, Dictionary param, Dictionary headers)string result = string.Empty;trystring paramData = “;if (param != null foreach (var item in param)if (sbuilder.Length 0)sbuilder.Append(“sbuilder.Append(item.Key + “=“ + item.Value);paramData = sbuilder.ToString();method = met
4、hod.ToUpper();if (method = “GET“)url = string.Format(“0?1“, url, paramData);HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.Create(url);if (method = “GET“)wbRequest.Method = “GET“;else if (method = “POST“)wbRequest.Method = “POST“;wbRequest.ContentType = “application/x-www-form- urlencoded“;wb
5、Request.ContentLength = Encoding.UTF8.GetByteCount(paramData);using (Stream requestStream = wbRequest.GetRequestStream()using (StreamWriter swrite = new StreamWriter(requestStream)swrite.Write(paramData);HttpWebResponse wbResponse = (HttpWebResponse)wbRequest.GetResponse();using (Stream responseStre
6、am = wbResponse.GetResponseStream()using (StreamReader sread = new StreamReader(responseStream)result = sread.ReadToEnd();catchreturn “;return result;class Responsepublic string statusCode;static void Main(string args)string method = “POST“;string url = “https:/ param = new Dictionary(); param.Add(“
7、apiKey“, “your_api_key“); /需要从获取 param.Add(“page“, “); /页码(默认为1) param.Add(“pageSize“, “); /每页条数(范围10,20,默认10条) Dictionary headers = null;string result = apishop_send_request(method, url, param, headers);if (result = “)/返回内容异常,发送请求失败Console.WriteLine(“发送请求失败“);return;Response res = new JavaScriptSer
8、ializer().Deserialize(result);if (res.statusCode = “000000“)/状态码为000000, 说明请求成功Console.WriteLine(string.Format(“请求成功: 0“, result);else/状态码非000000, 说明请求失败Console.WriteLine(string.Format(“请求失败: 0“, result);Console.ReadLine(); 2.搜索虚搜索虚拟币拟币 using System; using System.Collections.Generic; using System.IO
9、; using System.Net; using System.Text; using System.Web.Script.Serialization;namespace apishop_sdk class Program/* 转发请求到目的主机* param method string 请求方法* param url string 请求地址* param params Dictionary 请求参数* param headers Dictionary 请求头* return string*/static string apishop_send_request(string method,
10、string url, Dictionary param, Dictionary headers)string result = string.Empty;trystring paramData = “;if (param != null foreach (var item in param)if (sbuilder.Length 0)sbuilder.Append(“sbuilder.Append(item.Key + “=“ + item.Value);paramData = sbuilder.ToString();method = method.ToUpper();if (method
11、= “GET“)url = string.Format(“0?1“, url, paramData);HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.Create(url);if (method = “GET“)wbRequest.Method = “GET“;else if (method = “POST“)wbRequest.Method = “POST“;wbRequest.ContentType = “application/x-www-form- urlencoded“;wbRequest.ContentLength = E
12、ncoding.UTF8.GetByteCount(paramData);using (Stream requestStream = wbRequest.GetRequestStream()using (StreamWriter swrite = new StreamWriter(requestStream)swrite.Write(paramData);HttpWebResponse wbResponse = (HttpWebResponse)wbRequest.GetResponse();using (Stream responseStream = wbResponse.GetRespon
13、seStream()using (StreamReader sread = new StreamReader(responseStream)result = sread.ReadToEnd();catchreturn “;return result;class Responsepublic string statusCode;static void Main(string args)string method = “POST“;string url = “https:/ param = new Dictionary(); param.Add(“apiKey“, “your_api_key“);
14、 /需要从获取 param.Add(“keyword“, “); /搜索关键字 param.Add(“page“, “); /页码(默认为1) param.Add(“pageSize“, “); /每页条数(范围10,20,默认每页10条) Dictionary headers = null;string result = apishop_send_request(method, url, param, headers);if (result = “)/返回内容异常,发送请求失败Console.WriteLine(“发送请求失败“);return;Response res = new Java
15、ScriptSerializer().Deserialize(result);if (res.statusCode = “000000“)/状态码为000000, 说明请求成功Console.WriteLine(string.Format(“请求成功: 0“, result);else/状态码非000000, 说明请求失败Console.WriteLine(string.Format(“请求失败: 0“, result);Console.ReadLine(); 3.查询查询虚虚拟币详拟币详情情 using System; using System.Collections.Generic; using System.IO; using System.