使用Zephyr为Jira Cloud提供.Net的ZAPI

时间:2017-01-26 21:39:26

标签: c# rest jira

我已经整理了一些我的解决方案,我终于能够得到Zephyr的回复了,但当我知道它可用时,它给了我404响应。是否有其他人试图使用ZAPI报告测试数据?

秘密和访问密钥来自Zephyr添加的Jira页面。项目密钥来自Jira。这是我的代码和它给我的响应:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net.Http.Headers;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using Jira.SDK.Domain;
using JWT;

namespace WebPortalUITests.Controllers
{
    [TestClass]
    public class Reporting
    {
        static string User = "My.User.Name";
        static string Password = "My.Password";
        static string jiraBaseUrl = "https://mycompany.atlassian.net/";
        static string zephyrBaseUrl = "https://prod-api.zephyr4jiracloud.com/connect";
        static string Secret = "P1oihENe5PLUS_THE_REST_OF_MY_SECRET";
        static string AccessKey = "amlyYTox_PLUS_THE_REST_OF_MY_KEY";

        public async Task<bool> CycleExists(string Name)
        {
            //connect to Jira to get project and version IDs using the Jira.SDK library
            Jira.SDK.Jira jira = new Jira.SDK.Jira();
            jira.Connect(jiraBaseUrl, User, Password);
            Project webPortal = jira.GetProject("WP");
            long id = webPortal.ID;
            long version = webPortal.ProjectVersions.Last<ProjectVersion>().ID;

            //format the Zephyr request and use it to generate a JWT
            string request = "/connect/public/rest/api/1.0/cycles/search?versionId=" + version + "&projectId=" + id;
            string finalAPI = zephyrBaseUrl + request;
            string token = JsonWebToken.Encode(finalAPI, Secret, JwtHashAlgorithm.HS256);

            //put the JWT and the accesskeys in the header and request the info
            using (var httpClient = new HttpClient { BaseAddress = new Uri(zephyrBaseUrl)})
            {
                httpClient.DefaultRequestHeaders.Accept.Clear();
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("authorization", "JWT "+token);
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("zapiaccesskey", AccessKey);

                using (var response = httpClient.GetAsync(string.Format(request)).Result)
                {
                    string responseData = await response.Content.ReadAsStringAsync();

                }
                return true;
            }
        }

    }
}   
  • response {StatusCode:404,ReasonPhrase:&#39; Not Found&#39;,Version:1.1,Content:System.Net.Http.StreamContent,Headers: { 连接:保持活力 日期:2017年1月26日星期四20:34:01 GMT 服务器:Apache-Coyote / 1.1 内容长度:0 System.Net.Http.HttpResponseMessage

0 个答案:

没有答案