资源预览内容
第1页 / 共10页
第2页 / 共10页
第3页 / 共10页
第4页 / 共10页
第5页 / 共10页
第6页 / 共10页
第7页 / 共10页
第8页 / 共10页
第9页 / 共10页
第10页 / 共10页
亲,该文档总共10页全部预览完了,如果喜欢就下载吧!
资源描述
本文格式为Word版,下载可任意编辑基于C的汇率接口调用代码实例 基于C#的汇率接口调用代码实例 代码描述:基于C#的汇率接口调用代码实例 代码平台:聚合数据 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; using Xfrog.Net; using System.Diagnostics; using System.Web; /- / 汇率调用例如代码 聚合数据 / 在线接口文档: / 代码中JsonObject类下载地址: /- namespace ConsoleAPI class Program static void Main(string args) string appkey = ; /配置您申请的appkey /1.常用汇率查询 string url1 = ; var parameters1 = new Dictionary(); parameters1.Add(, appkey);/你申请的key string result1 = sendPost(url1, parameters1, ); JsonObject newObj1 = new JsonObject(result1); String errorCode1 = newObj1.Value; if (errorCode1 = ) Debug.WriteLine(告成); Debug.WriteLine(newObj1); else /Debug.WriteLine(失败 Debug.WriteLine(newObj1.Value+newObj1.Value); /2.货币列表 string url2 = ; var parameters2 = new Dictionary(); parameters2.Add(, appkey);/你申请的key string result2 = sendPost(url2, parameters2, ); JsonObject newObj2 = new JsonObject(result2); String errorCode2 = newObj2.Value; if (errorCode2 = ) Debug.WriteLine(告成); Debug.WriteLine(newObj2); else /Debug.WriteLine(失败 Debug.WriteLine(newObj2.Value+newObj2.Value); /3.实时汇率查询换算 string url3 = ; var parameters3 = new Dictionary(); parameters3.Add( , ); /转换汇率前的货币代码 parameters3.Add( , ); /转换汇率成的货币代码 parameters3.Add(, appkey);/你申请的key string result3 = sendPost(url3, parameters3, ); JsonObject newObj3 = new JsonObject(result3); String errorCode3 = newObj3.Value; if (errorCode3 = ) Debug.WriteLine(告成); Debug.WriteLine(newObj3); else /Debug.WriteLine(失败 Debug.WriteLine(newObj3.Value+newObj3.Value); / / Http (GET/POST) / / / / / 响应内容 static string sendPost(string url, IDictionary parameters, string method) if (method.ToLower() = ) HttpWebRequest req = null; HttpWebResponse rsp = null; System.IO.Stream reqStream = null; try req = (HttpWebRequest)WebRequest.Create(url); req.Method = method; req.KeepAlive = false; req.ProtocolVersion = HttpVersion.Version10; req.Timeout = 5000; req.ContentType = d;charset=utf-8; byte postData = Encoding.UTF8.GetBytes(BuildQuery(parameters, ); reqStream = req.GetRequestStream(); reqStream.Write(postData, 0, postData.Length); rsp = (HttpWebResponse)req.GetResponse(); Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet); return GetResponseAsString(rsp, encoding); catch (Exception ex) return ex.Message; finally if (reqStream != null) reqStream.Close(); if (rsp != null) rsp.Close(); else /创造苦求 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + + BuildQuery(parameters, ); /GET苦求 request.Method = ; request.ReadWriteTimeout = 5000; request.ContentType = ; HttpWebResponse response = (HttpWebResponse
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号