java如何修复服务器返回的HTTP响应代码400和无法处理的转换
我试图通过java编码来进行JIRA转换,大部分时间都是这样,但JIRA rest api调用有时会返回以下错误:(实际上,有了这个错误,转换就被处理了)
java.io.IOException: Server returned HTTP response code: 400 for URL: http://testingSite/jira/rest/api/latest/issue/ABC-123/transitions
另外,在某些情况下,RESTAPI调用不会返回错误,但转换不会继续
这是我的代码,大部分时间都是有效的,所以它毁了我的日子去弄清楚发生了什么
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:服务器返回HTTP响应代码:400,但已处理转换
行为2:服务器不返回任何错误,但未处理转换
# 1 楼答案
所以我在寻找参考文档here。其声明是
你有你的转换id硬编码,可能对于这种类型的问题,它有不同的转换id或类似的东西。试着打电话
验证您的转换是否确实存在