public class GemfireTest extends SecurityManager {
public static void main(String[] args) throws NameResolutionException, TypeMismatchException, QueryInvocationTargetException, FunctionDomainException, IOException {
System.setProperty("gemfire.locators", "localhost[8091]");
Properties properties = new Properties();
ServerLauncher serverLauncher = new ServerLauncher.Builder()
.setMemberName("server1")
.setServerPort(40404)
.set("start-locator", "localhost[8091]")
.build();
serverLauncher.start();
System.out.println(serverLauncher.status());
String restapi ="http://localhost:8091/gemfire-api/v1/";
// URLConnection urlConnection = new URL(restapi).openConnection();
try {
URL obj = new URL(restapi);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("accept","application/json");
int responseCode = con.getResponseCode();
System.out.println(responseCode);
// if (responseCode == HttpURLConnection.HTTP_OK) { // success
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// print result
System.out.println("reason"+response.toString());
获取响应代码:-1,无效的 Http 响应。
我该如何解决这个问题?
相关分类