基于C的汇率接口调用代码实例

上传人:闪**** 文档编号:290682748 上传时间:2022-05-10 格式:DOCX 页数:10 大小:17.62KB
返回 下载 相关 举报
基于C的汇率接口调用代码实例_第1页
第1页 / 共10页
基于C的汇率接口调用代码实例_第2页
第2页 / 共10页
基于C的汇率接口调用代码实例_第3页
第3页 / 共10页
基于C的汇率接口调用代码实例_第4页
第4页 / 共10页
基于C的汇率接口调用代码实例_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《基于C的汇率接口调用代码实例》由会员分享,可在线阅读,更多相关《基于C的汇率接口调用代码实例(10页珍藏版)》请在金锄头文库上搜索。

1、本文格式为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; /- / 汇率调用例如代码 聚合数据 / 在线接口文档: / 代码中Json

2、Object类下载地址: /- 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(result

3、1); 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(url

4、2, 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();

5、 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); e

6、lse /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 re

7、q = (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.W

8、rite(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

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 大杂烩/其它

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