【问题标题】:ATLASSIAN JIRA C# REST POSTATLASSIAN JIRA C# REST POST
【发布时间】:2013-08-18 23:29:25
【问题描述】:

我想使用 REST 帖子从 MS SSIS 进程发送数据:

    json = json + "{ ";
        json = json + "\"fields\": {";
        json = json + "\"project\": {  \"id\": \"XXX\" },";
        json = json + "\"summary\": \"REST ye merry gentlemen.\",";
        json = json + "\"description\": \"Hellow\",";
        json = json + "\"issuetype\": { \"name\": \"Bug\" }";
        json = json + "} ";
        json = json + "} ";


        var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://xxx.atlassian.net/rest/api/2/issue/");
        httpWebRequest.ContentType = "application/json";
        httpWebRequest.Method = "POST";


        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {

            MessageBox.Show(json);

            streamWriter.Write(json);
        }

        string mergedCredentials = string.Format("{0}:{1}", "xxx", "xxx");
        byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
        string credentials = Convert.ToBase64String(byteCredentials);

        //httpWebRequest.Headers.Add("Authorization", "Basic " + credentials);

        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            var responseText = streamReader.ReadToEnd();
            //Now you have your response.
            //or false depending on information in the response

        } 

服务器响应:

SSIS 包“Package.dtsx”正在启动。错误:脚本任务中的 0x1: System.Reflection.TargetInvocationException: Het doel van een aanroep heeft een uitzdering veroorzaakt。 ---> System.Net.WebException: 德 外部服务器 heeft een fout geretourneerd:(400) Ongeldige opdracht。 bij System.Net.HttpWebRequest.GetResponse() bij ST_8fbfe559ee824ef19f7c9bc2c425effc.csproj.ScriptMain.Main() --- Einde van intern uitzonderingsstackpad --- bij System.RuntimeMethodHandle._InvokeMethodFast(对象目标,对象 [] 参数,SignatureStruct& sig,MethodAttributes 方法属性, RuntimeTypeHandle typeOwner) bij System.Reflection.RuntimeMethodInfo.Invoke(对象 obj,BindingFlags invokeAttr、Binder binder、Object[] 参数、CultureInfo 文化、 Boolean skipVisibilityChecks) bij System.Reflection.RuntimeMethodInfo.Invoke(对象 obj,BindingFlags invokeAttr、Binder binder、Object[] 参数、CultureInfo 文化)
bij System.RuntimeType.InvokeMember(字符串名称,BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] 修饰符、CultureInfo 文化、String[] 命名参数) bij Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript() 任务失败:脚本任务警告:包中的 0x80019002:SSIS 警告 代码 DTS_W_MAXIMUMERRORCOUNTREACHED。执行方法成功, 但是引发的错误数 (1) 达到了允许的最大值 (1); 导致失败。当错误数量达到 MaximumErrorCount 中指定的数字。更改 MaximumErrorCount 或修复错误。 SSIS 包“Package.dtsx” 完成:失败。

错误信息的英文位是

调用的目的导致了异常。 ---> System.Net.WebException:远程服务器返回错误:(400) 错误的请求

【问题讨论】:

标签: c# ssis jira


【解决方案1】:

我用我的应用程序测试了你的 JSON,它似乎是正确的(假设你的 projectId 和 issueTypeName 对你的 Jira 是正确的)。 (EDIT2:确保为您创建的 issueType 发送所有必填字段)。

但是,为什么不在标题中添加授权?

另外,我在发布之前将我的 JSON 编码为 UTF8。不确定您的 StreamWriter 是否也这样做。 (EDIT1:好的,抱歉,StreamWriter 编码为 UTF-8,但我的代码仍然与 request.ContentLength 和 request.Accept 不同,不确定是否会有所不同)

byte[] data = Encoding.UTF8.GetBytes(postData);
request.Accept = "application/json";
request.ContentLength = data.Length;
using (Stream requestStream = request.GetRequestStream())
{
    requestStream.Write(data, 0, data.Length);
}

如果这个 sn-p 对你没有帮助,我可以添加我所有的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-25
    • 2020-11-23
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-23
    相关资源
    最近更新 更多