お世話になります。
C#の勉強をしたいと思い
下記のサイトより
https://kokenji.net/coincheck-api/
コードを拝借してAPIを実行してみましたが
どうしてもinternal async Task<string>の Sendの部分で
CS0116のエラーが回避出来ず先輩方のお力をお借りしようと思い書き込みをさせていただきました。
丸投げするのも自分のためにならないので
このサイトを見たら解決できるやヒントなどを頂けると助かります。
お忙しいところ大変恐縮ですがよろしくお願いします
コードは下記のとおりです。
C#
1using System; 2using System.Collections.Generic; 3using System.Net.Http; 4using System.Security.Cryptography; 5using System.Text; 6using System.Threading.Tasks; 7using System.Windows.Forms; 8namespace Crypto_Currency 9{ 10 public partial class Form1 : Form 11 { 12 public Form1() 13 { 14 InitializeComponent(); 15 } 16 17 private void Form1_Load(object sender, EventArgs e) 18 { 19 20 } 21 22 private async void button1_ClickAsync(object sender, EventArgs e) 23 { 24 //coincheck取引所にアクセスする HttpClient 25 HttpClient http = new HttpClient(); 26 http.BaseAddress = new Uri("https://coincheck.com"); 27 28 //板情報を取得 29 Uri path = new Uri("/api/order_books", UriKind.Relative);//APIの通信URL 30 string apiKey = "XXXXX";//APIキー 31 string secret = "XXXXX";//秘密キー 32 string method = "GET";//APIメソッド 33 string json = await Send(http, path, apiKey, secret, method); 34 35 36 } 37 } 38 39/// <summary>coincheck取引所のAPIを実行します。 40/// </summary> 41/// <param name="http">取引所と通信する HttpClient。</param> 42/// <param name="path">APIの通信URL(取引所サイトからの相対)。</param> 43/// <param name="apiKey">APIキー。</param> 44/// <param name="secret">秘密キー。</param> 45/// <param name="method">APIのメソッド名。</param> 46/// <param name="parameters">APIのパラメータのリスト(Key:パラメータ名, Value:パラメータの値)。</param> 47/// <returns>レスポンスとして返されるJSON形式の文字列。</returns> 48internal async Task<string> Send(HttpClient http, Uri path, string apiKey, string secret, string method, Dictionary<string, string> parameters = null) 49{ 50 if (parameters == null) 51 parameters = new Dictionary<string, string>(); 52 53 // パラメータ文字列を作成 54 var content = new FormUrlEncodedContent(parameters); 55 string param = await content.ReadAsStringAsync(); 56 57 // nonceにunixtimeを用いる 58 string nonce = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); 59 60 // POSTするメッセージを作成 61 var uri = new Uri(http.BaseAddress, path); 62 string message = nonce + uri.ToString() + param; 63 64 // メッセージをHMACSHA256で署名 65 byte[] hash = new HMACSHA256(Encoding.UTF8.GetBytes(secret)).ComputeHash(Encoding.UTF8.GetBytes(message)); 66 string sign = BitConverter.ToString(hash).ToLower().Replace("-", "");//バイト配列をを16進文字列へ 67 68 // HTTPヘッダをセット 69 http.DefaultRequestHeaders.Clear(); 70 http.DefaultRequestHeaders.Add("ACCESS-KEY", apiKey); 71 http.DefaultRequestHeaders.Add("ACCESS-NONCE", nonce); 72 http.DefaultRequestHeaders.Add("ACCESS-SIGNATURE", sign); 73 74 // 送信 75 HttpResponseMessage res; 76 if (method == "POST") 77 { 78 res = await http.PostAsync(path, content); 79 } 80 else if (method == "GET") 81 { 82 res = await http.GetAsync(path); 83 } 84 else 85 { 86 throw new ArgumentException("method は POST か GET を指定してください。", method); 87 } 88 89 //返答内容を取得 90 string text = await res.Content.ReadAsStringAsync(); 91 92 //通信上の失敗 93 if (!res.IsSuccessStatusCode) 94 return ""; 95 96 return text; 97} 98}

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/01 05:04