Java
Java
Send a Bodyless REST Request into a StringBuilder
See more REST Examples
Demonstrates Rest.FullRequestNoBodySb, which sends a request with no body and stores the text response body in a StringBuilder.
Background. This variant of the no-body full request writes the response into a StringBuilder rather than returning it as a string, which is convenient when the response will be further processed in place.
Chilkat Java Downloads
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[])
{
boolean success = false;
CkRest rest = new CkRest();
boolean bTls = true;
boolean bAutoReconnect = true;
success = rest.Connect("example.com",443,bTls,bAutoReconnect);
if (success == false) {
System.out.println(rest.lastErrorText());
return;
}
// FullRequestNoBodySb sends a request with no body and stores the text response body in a
// StringBuilder.
CkStringBuilder sbResponse = new CkStringBuilder();
success = rest.FullRequestNoBodySb("GET","/api/items/123",sbResponse);
if (success == false) {
System.out.println(rest.lastErrorText());
return;
}
String responseText = sbResponse.getAsString();
if (sbResponse.get_LastMethodSuccess() == false) {
System.out.println(sbResponse.lastErrorText());
return;
}
System.out.println(responseText);
}
}