問題 ID の特定のリストから JIRA から問題を取得する小さなアプリを開発していますが、それらのいくつかは存在せず、API 呼び出しは 400 Bad Request メッセージを返します。
これは私がこれまでに持っているコードの関連ブロックです(C#):
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(thejiraurl);
request.Method = "GET";
request.ContentType = "Content-Type: application/json";
request.Accept = "application/json";
string mergedCredentials = "thecredentials :)";
byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
string encodedCredentials = Convert.ToBase64String(byteCredentials);
request.Headers.Add("Authorization", "Basic " + encodedCredentials);
try
{
WebResponse response = request.GetResponse(); //this line breaks because some records don't exist anymore, that's ok, but at least I need to know which ones! those are found in the response that I can't see here but I can with Fiddler! @.@
Stream data = response.GetResponseStream();
}
catch(WebException ex)
{
Console.WriteLine(ex.Message);
if(ex.Status == WebExceptionStatus.ProtocolError)
{
Console.WriteLine("Status Code : {0}", ((HttpWebResponse)ex.Response).StatusCode); //This is 'BadRequest'
Console.WriteLine("Status Description : {0}", ((HttpWebResponse)ex.Response).StatusDescription); //This is 'Bad Request'
using (Stream responseStream = ex.Response.GetResponseStream())
using (StreamReader responseReader = new StreamReader(responseStream))
{
string responseMessage = responseReader.ReadToEnd(); //This is a long message but do not has the errormessages seen with Fiddler (and even in a internet browser)
Console.WriteLine(responseMessage);
}
}
}
ただし、Fiddler を使用すると、次のような実際のエラー メッセージが返されることがわかります。
{"errorMessages":["A value with ID '1' does not exist for the field 'key'."],"errors":{}}
C# または vb を使用してこのメッセージを取得するにはどうすればよいですか?
これは質問に非常に似ていますが、それは Java を使用したものです: httpurl接続
助けていただければ幸いです。