简体   繁体   English

HTTP 连接到 JIRA XRAY Rest API 不工作

[英]HTTP connection to JIRA XRAY Rest API not working

Need help I am trying to connect to XRAY JIRA using Rest API and want to execute a case but getting 400 error response at step inputStream=new InputStreamReader(con.getInputStream(),"UTF-8")需要帮助 我正在尝试使用 Rest API 连接到 XRAY JIRA 并想执行一个案例,但在步骤inputStream=new InputStreamReader(con.getInputStream(),"UTF-8")得到 400 错误响应

java.io.IOException: Server returned HTTP response code: 400 for URL: java.io.IOException:服务器返回 HTTP 响应代码:URL 为 400:

My Code is below:我的代码如下:

    *HttpURLConnection con=null;
    InputStreamReader inputStream=null;
        URL jira_API_URL=new URL("https://jira.abc.com/rest/raven/latest/import/execution");
        
        
          String encodeCredentials=Base64.getEncoder().encodeToString(
          "kkris:testjira@234".getBytes("UTF-8"));
          con=(HttpURLConnection)jira_API_URL.openConnection();
          con.setRequestMethod("POST"); con.setDoOutput(true);
          con.setRequestProperty("Autherization", "Basic "+encodeCredentials);
          con.setRequestProperty("Content-Type", "application/json");
          con.setRequestProperty("X-Atlassian-Token", "nocheck");
         
                 

        try(OutputStream os=con.getOutputStream()){
            byte[] input=json.toString().getBytes("UTF-8");
            os.write(input,0,input.length);
        }
        inputStream=new InputStreamReader(con.getInputStream(),"UTF-8");*

Note :Would like to add that I am able to hit this RestAPI using postman and Restassured & able to execute testcase in XRAYJIRA successfully注意:想补充一点,我能够使用 postman 访问此 RestAPI 并且放心并能够在 XRAYJIRA 中成功执行测试用例

Well, first of all we need to clarify if you have Xray on Jira server/datacenter or Xray on Jira cloud, as they are different products and the APIs are also slightly different.好吧,首先我们需要弄清楚你是在 Jira 服务器/数据中心上安装了 Xray,还是在 Jira 云上安装了 Xray,因为它们是不同的产品,API 也略有不同。 From your example, it seems that you're targetting Xray on Jira server/datacenter, and that you aim to import results using the Xray JSON format and respective endpoint as detailed here .从您的示例来看,您的目标似乎是 Jira 服务器/数据中心上的 Xray,并且您的目标是使用 Xray JSON 格式和相应的端点导入结果,详见此处 The endpoint URL in that case should either be <jira_base_url>/rest/raven/1.0/import/execution or <jira_base_url>/rest/raven/2.0/import/execution在这种情况下,端点 URL 应该是 <jira_base_url>/rest/raven/1.0/import/execution 或 <jira_base_url>/rest/raven/2.0/import/execution

Also, please make sure the Xray JSON content you submit follows this syntax .另外,请确保您提交的 Xray JSON 内容遵循此语法

Note: you may want to have a look at this repo which contains some sample code for submiting results in Java and other languages, including a proof-of-concept client api .注意:您可能想看看这个 repo ,其中包含一些示例代码,用于提交 Java 和其他语言的结果,包括概念验证客户端 api

The response body content may show you clues about what's wrong.响应正文内容可能会向您显示错误的线索。 You can start by using curl utility first as shown here and then implement the java code.您可以先使用curl实用程序开始,如此处所示,然后实施 java 代码。

curl -H "Content-Type: application/json" -X POST -u admin:admin --data @data.json http://yourserver/rest/raven/1.0/import/execution

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM