私は 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 応答の一部にアクセスする最善の方法は何ですか?
どうもありがとう
ポール