如何修复服务器返回 HTTP 响应代码 400 且无法处理转换
How to fix the Server returned HTTP response code 400 and tranisitions cannot be processed
我正在尝试通过 java 编码来进行 JIRA 转换,大部分时间它都有效,但 jira rest api 有时会调用 return 以下错误:(实际上有这个错误,转换被处理)
java.io.IOException: Server returned HTTP response code: 400 for URL: http://testingSite/jira/rest/api/latest/issue/ABC-123/transitions
此外,在某些情况下,其余 api 调用不会 return 错误,但不会继续进行转换。
这是我的编码,大部分时间它都能正常工作,所以它毁了我的日子来弄清楚发生了什么。
try {
String authkey = "YWRtaW46cGFzc3dvcmQ=";
URL url = new URL("http://testingSite/jira/rest/api/latest/issue/ABC-123/transitions");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Basic " + authkey);
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
OutputStream os = connection.getOutputStream();
String data = "{\"transition\": {\"id\": \"71\"}}";
os.write(data.toString().getBytes("UTF-8"));
os.close();
content = connection.getInputStream();
in = new InputStreamReader(content);
br = new BufferedReader(in);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
错误来自这一行:
content = connection.getInputStream();
我希望不会有异常,并且所有转换都已处理,但这种行为对我来说很奇怪。
行为 1:服务器 returned HTTP 响应代码:400 但转换已处理
行为 2:服务器没有 return 任何错误,但未处理转换
所以我在寻找参考文档here。它说
POST: 400 - If there is no transition specified.
您对转换 ID 进行了硬编码,并且对于此类问题,它可能具有不同的转换 ID 或类似的东西。尝试调用
GET /rest/api/2/issue/{issueIdOrKey}/transitions?{transitionId}
验证您的转换确实存在。
我正在尝试通过 java 编码来进行 JIRA 转换,大部分时间它都有效,但 jira rest api 有时会调用 return 以下错误:(实际上有这个错误,转换被处理)
java.io.IOException: Server returned HTTP response code: 400 for URL: http://testingSite/jira/rest/api/latest/issue/ABC-123/transitions
此外,在某些情况下,其余 api 调用不会 return 错误,但不会继续进行转换。
这是我的编码,大部分时间它都能正常工作,所以它毁了我的日子来弄清楚发生了什么。
try {
String authkey = "YWRtaW46cGFzc3dvcmQ=";
URL url = new URL("http://testingSite/jira/rest/api/latest/issue/ABC-123/transitions");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Basic " + authkey);
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
OutputStream os = connection.getOutputStream();
String data = "{\"transition\": {\"id\": \"71\"}}";
os.write(data.toString().getBytes("UTF-8"));
os.close();
content = connection.getInputStream();
in = new InputStreamReader(content);
br = new BufferedReader(in);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
错误来自这一行:
content = connection.getInputStream();
我希望不会有异常,并且所有转换都已处理,但这种行为对我来说很奇怪。
行为 1:服务器 returned HTTP 响应代码:400 但转换已处理
行为 2:服务器没有 return 任何错误,但未处理转换
所以我在寻找参考文档here。它说
POST: 400 - If there is no transition specified.
您对转换 ID 进行了硬编码,并且对于此类问题,它可能具有不同的转换 ID 或类似的东西。尝试调用
GET /rest/api/2/issue/{issueIdOrKey}/transitions?{transitionId}
验证您的转换确实存在。