使用java连接到jira服务器时出现404错误

2izufjch  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(420)

我试图用java连接jira服务器,我收到“404错误”。我正在分享的基本网址和代码,我试图用它来连接jira服务器,请让我知道什么是错误的

  1. public class Automate {
  2. public static void main(String[] args) {
  3. String baseURL = "https://thread.atlassian.net/";
  4. String loginURL = "auth/1/session";
  5. String loginUserName = "*********.com";
  6. String loginPassword = "*******";
  7. if (!errorOccurred) {
  8. loginResponse = loginToJira(baseURL, loginURL, loginUserName, loginPassword);
  9. if (loginResponse == "ERROR") {
  10. errorOccurred = true;
  11. }
  12. }
  13. public static String loginToJira(String baseURL, String loginURL, String loginUserName, String loginPassword) {
  14. String loginResponse = "";
  15. URL url = null;
  16. HttpURLConnection conn = null;
  17. String input = "";
  18. OutputStream outputStream = null;
  19. BufferedReader bufferedReader = null;
  20. String output = null;
  21. try {
  22. //Create URL
  23. url = new URL(baseURL + loginURL);
  24. //Use URL to create connection
  25. conn = (HttpURLConnection) url.openConnection();
  26. //Set properties
  27. conn.setDoOutput(true);
  28. conn.setRequestMethod("POST");
  29. conn.setRequestProperty("content.type", "application/json");
  30. //Create Json post object
  31. input = "{\"Username\" :\"" + loginUserName + "\" \"Password\" :\"" + loginPassword + "\"}";
  32. //Send our request
  33. outputStream = conn.getOutputStream();
  34. //System.out.println("outputStream:"+outputStream);
  35. outputStream.write(input.getBytes());
  36. //System.out.println("outputStream after writing input:"+outputStream);
  37. outputStream.flush();
  38. //System.out.println("outputStream after Flushing:"+outputStream);
  39. //Handle our response
  40. System.out.println("Get Response :"+ conn.getResponseCode() );
  41. if (conn.getResponseCode() == 200) {
  42. bufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  43. System.out.println("Connection Stream:"+bufferedReader);
  44. while ((output = bufferedReader.readLine()) != null) {
  45. loginResponse += output;
  46. }
  47. conn.disconnect();
  48. }
  49. } catch (Exception ex) {
  50. //Handle errors
  51. System.out.println("Error in login Jira" + ex.getMessage());
  52. return loginResponse = "ERROR";
  53. }
  54. System.out.println("\nloginResponse:");
  55. System.out.println(loginResponse);
  56. return loginResponse;
  57. }
  58. }
dohp0rv5

dohp0rv51#

请再次检查网址。即使从浏览器访问,该页也不存在。尝试在重定向到登录时仅使用基本url或其他登录url。

相关问题