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

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

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

public class Automate {
    public static void main(String[] args) {
    String baseURL = "https://thread.atlassian.net/";
        String loginURL = "auth/1/session";
        String loginUserName = "*********.com";
        String loginPassword = "*******";
if (!errorOccurred) {
            loginResponse = loginToJira(baseURL, loginURL, loginUserName, loginPassword);
            if (loginResponse == "ERROR") {
                errorOccurred = true;
            }
        }
public static String loginToJira(String baseURL, String loginURL, String loginUserName, String loginPassword) {
        String loginResponse = "";
        URL url = null;
        HttpURLConnection conn = null;
        String input = "";
        OutputStream outputStream = null;
        BufferedReader bufferedReader = null;
        String output = null;
        try {
            //Create URL
            url = new URL(baseURL + loginURL);
            //Use URL to create connection
            conn = (HttpURLConnection) url.openConnection();
            //Set properties
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("content.type", "application/json");
            //Create Json post object
            input = "{\"Username\" :\"" + loginUserName + "\" \"Password\" :\"" + loginPassword + "\"}";
            //Send our request
            outputStream = conn.getOutputStream();
            //System.out.println("outputStream:"+outputStream);
            outputStream.write(input.getBytes());
            //System.out.println("outputStream after writing input:"+outputStream);
            outputStream.flush();
            //System.out.println("outputStream after Flushing:"+outputStream);
            //Handle our response
            System.out.println("Get Response :"+ conn.getResponseCode() );
            if (conn.getResponseCode() == 200) {
                bufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                System.out.println("Connection Stream:"+bufferedReader);
                while ((output = bufferedReader.readLine()) != null) {
                    loginResponse += output;

                }
                conn.disconnect();
            }
        } catch (Exception ex) {
            //Handle errors
            System.out.println("Error in login Jira" + ex.getMessage());
            return loginResponse = "ERROR";
        }
        System.out.println("\nloginResponse:");
        System.out.println(loginResponse);
        return loginResponse;
    }
}
dohp0rv5

dohp0rv51#

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

相关问题