Java
Chilkat2 Java
Example: Http.QuickGetStr method
Demonstrates theQuickGetStr method.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
public class ChilkatExample {
public static void main(String[] args) {
Http http = new Http();
// Keep the response body if there's an error.
http.setKeepResponseBody(true);
// Send the HTTP GET and return the content in a string.
String str;
try {
str = http.quickGetStr("https://www.chilkatsoft.com/helloWorld.json");
} catch (ChilkatException e) {
if (http.getLastStatus() == 0) {
// Communications error. We did not get a response.
System.out.println(e.getLastErrorText());
} else {
System.out.println("Response status code: " + http.getLastStatus());
System.out.println("Response body error text:");
System.out.println(http.getLastResponseBody());
}
return;
}
System.out.println(str);
System.out.println("Success");
}
}