3

DotNetOpenAuth を使用して Jira と通信する際に問題が発生しました。

var payload =   
    new {
        fields = new
        {
            project = new { id = 10000 },
            summary = summary,
            description = description,
            issuetype = new { id = (int)issueTypeId }
        }
    };

webRequest = OAuthConsumer.PrepareAuthorizedRequest(
    new MessageReceivingEndpoint(url, HttpDeliveryMethods.PostRequest),
    accessToken
);

byte[] payloadContent = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(payload));
webRequest.ContentLength = payloadContent.Length;
using (var stream = webRequest.GetRequestStream())
{
    stream.Write(payloadContent, 0, payloadContent.Length);
}

ただし、 webRequest.GetRequestStream() は例外をスローするだけですThis property cannot be set after writing has started.

http://docs.atlassian.com/jira/REST/latest/#id120664を使用して新しい問題を作成しようとしています。OAuth ではなく基本認証を使用し、GET を使用した他のすべての OAuth 呼び出しが正常に機能する場合、コードは正常に機能します。

Jira で DotNetOpenAuth を使用する際のアドバイスはありますか?

ありがとう!

4

1 に答える 1

3

最後に問題を見つけました。次のコードを使用する必要があります。

var payload =   
    new {
        fields = new
        {
            project = new { id = 10000 },
            summary = summary,
            description = description,
            issuetype = new { id = (int)issueTypeId }
        }
    };

webRequest = OAuthConsumer.PrepareAuthorizedRequest(
    new MessageReceivingEndpoint(url, HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest),
    accessToken
);

webRequest.ContentType = "application/json";

byte[] payloadContent = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(payload));
webRequest.ContentLength = payloadContent.Length;
using (var stream = webRequest.GetRequestStream())
{
    stream.Write(payloadContent, 0, payloadContent.Length);
}

基本的に、HttpDeliveryMethods.AuthorizationHeaderRequest呼び出し時に追加する必要があり、ストリームに何かを追加する前にプロパティPrepareAuthorizedRequestを設定する必要がありました。ContentType

于 2013-03-12T14:45:40.120 に答える