【问题标题】:Using DotNetOpenAuth with Jira 5.1.2将 DotNetOpenAuth 与 Jira 5.1.2 一起使用
【发布时间】:2013-03-11 17:09:22
【问题描述】:

我在使用 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 调用都可以正常工作。

有人对使用 DotNetOpenAuth 和 Jira 有什么建议吗?

谢谢!

【问题讨论】:

    标签: c# jira dotnetopenauth


    【解决方案1】:

    终于找到问题了。需要使用以下代码:

    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);
    }
    

    基本上,我需要在调用PrepareAuthorizedRequest 时添加HttpDeliveryMethods.AuthorizationHeaderRequest,然后我需要在向流中添加任何内容之前设置ContentType 属性。

    【讨论】:

    • 您好,我正在尝试通过 RESAT API 和 OAuth 从我的 asp.net Web 应用程序访问 Jira。我无法让它工作。我需要有自己的客户端来实现 OpenIdClient 吗?我需要做什么?非常感谢。
    猜你喜欢
    • 2011-10-27
    • 1970-01-01
    • 2021-03-22
    • 2013-09-25
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多