31 rivejä
795 B
Java
31 rivejä
795 B
Java
package servlet;
|
|
|
|
import java.io.IOException;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
|
|
public class Get {
|
|
|
|
//private static final String USER_AGENT = "Mozilla/5.0";
|
|
|
|
private static final String GET_URL = "http://localhost:8080/Servlet_MBP/test";
|
|
|
|
|
|
|
|
public static void sendGET() throws IOException { // SUbscribe
|
|
URL obj = new URL(GET_URL);
|
|
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
|
con.setRequestMethod("GET");
|
|
//con.setRequestProperty("User-Agent", USER_AGENT);
|
|
int responseCode = con.getResponseCode();
|
|
System.out.println("GET Response Code :: " + responseCode);
|
|
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
|
System.out.println("Get success");
|
|
|
|
} else {
|
|
System.out.println("GET request not worked");
|
|
}
|
|
|
|
}
|
|
|
|
}
|