0

私は REST ベースのサービスを使用するのは初めてですが、やりたいことは非常に簡単だと思っていたことです。つまり、JIRA の問題を取得し、.NET Framework 4.5 クライアントを使用して表示することです。

次の URI をブラウザーに貼り付けることで、JSON 応答を取得できることがわかりました: https://jira.atlassian.com/rest/api/latest/issue/JRA-9

私がする必要があるのは、.net アプリからこれを呼び出すことです。そのため、いくつかの調査の結果、.NET 4.5 で HTTPClient を使用することが最善の方法であることがわかりました。

次のテスト コードを実行するには、.NET Framework 4.5 を参照し、System.Net.Http および拡張 System.Net.Http と System.Json への参照を追加する必要があります。

using System;
using System.Collections.Generic;
using System.Json;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace JIRAClient3
{
    class Program
    {
        static string _address = "https://jira.atlassian.com/rest/api/latest/issue/JRA-9";

        static async void Run()
        {
            // Create an HttpClient instance
            HttpClient client = new HttpClient();
            client.MaxResponseContentBufferSize = int.MaxValue;

            // Send a request asynchronously continue when complete
            HttpResponseMessage response = await client.GetAsync(_address);

            // Check that response was successful or throw exception
            response.EnsureSuccessStatusCode();

            // Read response asynchronously as JsonValue
            JsonArray content = await response.Content.ReadAsAsync<JsonArray>();

            // Exception occurs at the above line, which is:
            //System.InvalidOperationException was unhandled by user code
            //HResult=-2146233079
            //Message=The input stream contains too many delimiter characters which may 
            //be a sign that the incoming data may be malicious.
            //Source=System.Net.Http.Formatting

            // I then need to write out the contents of the JSON/JIRA issue.
      }

        static void Main(string[] args)
        {
             Run();
             Console.WriteLine("Hit ENTER to exit...");
             Console.ReadLine();
        }
    }
}

そのため、区切り記号が多すぎるという例外に固執しています。したがって、私の質問は次のとおりです。

  • これで正しい方向に向かっていますか?
  • 区切り記号が多すぎる例外を解決するにはどうすればよいですか。
  • 例外が解決されたら、JIRA 課題タイルや説明などの JSON 応答の一部にアクセスする最善の方法は何ですか?

どうもありがとう

ポール

4

1 に答える 1

0

http://forums.asp.net/post/4845421.aspxに掲載されている手順に従うことで、このエラーを回避できます。

ただし、次のASP.NETWebAPIのドロップ時にすぐに出荷されるJson.NETベースのフォーマッターを使用することをお勧めします。コードを自分でコンパイルするのを待ちたくない場合は、Microsoftのオープンソースリポジトリ( http://aspnetwebstack.codeplex.com/)から最新のコードを取得して、今すぐ入手できます。必要なフォーマッターは、具体的には次の場所にあります: http: //aspnetwebstack.codeplex.com/SourceControl/changeset/view/5ac8586b78b3#src%2fSystem.Net.Http.Formatting%2fFormatting%2fJsonMediaTypeFormatter.cs

于 2012-05-22T05:10:26.627 に答える