Get the response code 400 from RestAPI-Task

Hi, guys

I use the java to call the RestAPI for task, and the codes are below :

public class Test {
public static void main(String[] args) {
String s = DemoRestAPI.sendGet(“http://localhost:8080/engine-rest/task”);
System.out.println(s);

}

}

public class DemoRestAPI {

public static String sendGet(String httpurl) {
	
	HttpURLConnection connection;
	InputStream is = null;
	BufferedReader br = null;
	String result = null;
	try {
		URL url = new URL(httpurl);
		connection = (HttpURLConnection)url.openConnection();
		//Set the request method
		connection.setRequestMethod("GET");
		connection.setRequestProperty("Content-Type", "application/json");
		//ms
		connection.setConnectTimeout(15000);
		connection.setReadTimeout(60000);
		
		//send the request
		connection.connect();
		System.out.println(connection.getResponseCode());
		
		if (connection.getResponseCode() == 200) {
			is = connection.getInputStream();
			br = new BufferedReader(new InputStreamReader(is));

			StringBuffer sbf = new StringBuffer();
			String temp = null;
			while ((temp = br.readLine()) != null) {
				sbf.append(temp);
				sbf.append("\r\n");
			}
			result = sbf.toString();
		}
		
	}catch (MalformedURLException e) {
		e.printStackTrace();
	}catch (IOException e) {
		e.printStackTrace();
	}catch (Exception e){
		e.printStackTrace();
	}finally {
		if (br != null) {
			try {
				br.close();
			}catch (IOException e) {
				e.printStackTrace();
			}
		}
		if (is != null) {
			try {
				is.close();
			}catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	return result;
}

}

But I find I get the response code 400.
Everyone knows why?
The strange thing is that I get the response code 200 from the url : http://localhost:8080/engine-rest/deployment.

Are you able to reach the rest API via the browser or by using postman?

Hi @Niall
Yeah, both the browser and postman are OK.
So I feel so strange.

I solved the problem by changing the request method from GET to POST.