(Java) Example: Http.QuickGetStr method
Demonstrates the QuickGetStr method.
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
CkHttp http = new CkHttp();
// Keep the response body if there's an error.
http.put_KeepResponseBody(true);
// Send the HTTP GET and return the content in a string.
String str = http.quickGetStr("https://www.chilkatsoft.com/helloWorld.json");
if (http.get_LastMethodSuccess() == false) {
if (http.get_LastStatus() == 0) {
// Communications error. We did not get a response.
System.out.println(http.lastErrorText());
}
else {
System.out.println("Response status code: " + http.get_LastStatus());
System.out.println("Response body error text:");
System.out.println(http.lastResponseBody());
}
return;
}
System.out.println(str);
System.out.println("Success");
}
}
|