eoLinker-API_Shop_万智卡卡牌查询_API接口_C#调用示例代码

上传人:亿*** 文档编号:42471928 上传时间:2018-06-02 格式:DOCX 页数:9 大小:12.29KB
返回 下载 相关 举报
eoLinker-API_Shop_万智卡卡牌查询_API接口_C#调用示例代码_第1页
第1页 / 共9页
eoLinker-API_Shop_万智卡卡牌查询_API接口_C#调用示例代码_第2页
第2页 / 共9页
eoLinker-API_Shop_万智卡卡牌查询_API接口_C#调用示例代码_第3页
第3页 / 共9页
eoLinker-API_Shop_万智卡卡牌查询_API接口_C#调用示例代码_第4页
第4页 / 共9页
eoLinker-API_Shop_万智卡卡牌查询_API接口_C#调用示例代码_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《eoLinker-API_Shop_万智卡卡牌查询_API接口_C#调用示例代码》由会员分享,可在线阅读,更多相关《eoLinker-API_Shop_万智卡卡牌查询_API接口_C#调用示例代码(9页珍藏版)》请在金锄头文库上搜索。

1、eoLinker-API Shop 万智卡卡牌万智卡卡牌查询查询 C#调调用示例代用示例代码码万智卡卡牌万智卡卡牌查询查询获取炉万智牌信息,可获取全部,也可根据关键字查询某卡牌。该产该产品品拥拥有以下有以下APIs: :1.关键字获取卡牌列表2.获取卡牌列表3.获取卡牌信息注意,注意,该该示例代示例代码仅码仅适用于适用于 网站下网站下API 使用使用该产该产品前,您需要通品前,您需要通过过 https:/ 申申请请API服服务务1.关关键键字字获获取卡牌列表取卡牌列表 using System; using System.Collections.Generic; using System.I

2、O; 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,

3、 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

4、 = “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 =

5、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 responseStream = wbResponse.GetRespo

6、nseStream()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“)

7、; /需要从获取 param.Add(“keyword“, “); /关键字 param.Add(“page“, “); /当前页码(默认1) param.Add(“pageSize“, “); /当前页面卡牌数量(默认30) Dictionary headers = null;string result = apishop_send_request(method, url, param, headers);if (result = “)/返回内容异常,发送请求失败Console.WriteLine(“发送请求失败“);return;Response res = new JavaScriptS

8、erializer().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 Syste

9、m.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_send_request(string meth

10、od, 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 (met

11、hod = “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

12、 = 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 responseStream = wbResponse.GetRe

13、sponseStream()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_ke

14、y“); /需要从获取 param.Add(“page“, “); /当前页码(默认1) param.Add(“pageSize“, “); /当前页面卡牌数量(默认30) Dictionary headers = null;string result = apishop_send_request(method, url, param, headers);if (result = “)/返回内容异常,发送请求失败Console.WriteLine(“发送请求失败“);return;Response res = new JavaScriptSerializer().Deserialize(res

15、ult);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.Net; using System.Text; us

展开阅读全文
相关资源
相关搜索

当前位置:首页 > IT计算机/网络 > 开发文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号