2017-07-05 1 views
-2

REST OAuth 2.0をサポートするWebサイトからプロジェクトの詳細をダウンロードするためのC#コンソールアプリケーションを作成しようとしています。アクセストークンを使用してウェブサイトへのリクエスト/レスポンス呼び出しを行うにはどうすればよいですか?ここ は私のコードです:アクセストークンを使用してC#のWebサイトからプロジェクトのリストを取得するにはどうすればよいですか?

public string token = "4bjskfa2-b37d-6244-8413-3358b18c91b6"; 

public async Task GetProjectsAsync() 
{ 
    try 
    { 
     HttpClient client = new HttpClient(); 
     var projects = "https://app.rakenapp.com/api/v2/projects?" + token; 

     client.CancelPendingRequests(); 
     HttpResponseMessage output = await client.GetAsync(projects); 

     if (output.IsSuccessStatusCode) 
     { 
      string response = await output.Content.ReadAsStringAsync(); 
      project proj = JsonConvert.DeserializeObject<project>(response); 

      if (proj != null) 
      { 
       Console.WriteLine(proj.name); // You will get the projects here. 
      } 
     } 
    } 
    catch (Exception ex) 
    { 
     //catching the exception 
    } 

} 
+0

問題は何?また、なぜクライアントが作成されたばかりの保留中の要求を取り消したいのですか? –

答えて

0

あなたはあなたの要求にヘッダを追加する必要があります。

string url = "https://app.rakenapp.com/api/v2/projects"; 
using (var httpClient = new HttpClient()) 
     { 
      httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authorizationToken); 
      HttpResponseMessage response = await httpClient.GetAsync(url); 
      var contents = await response.Content.ReadAsStringAsync(); 
      var model = JsonConvert.DeserializeObject<project>.contents); 
      return model; 
     } 
+0

それは私のために働いた。どうもありがとう!! @iDebug – Rev4

関連する問題