Java
Chilkat2 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.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Rest;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
Rest rest = new Rest();
boolean bTls = true;
boolean bAutoReconnect = true;
try {
rest.connect("example.com", 443, bTls, bAutoReconnect);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// FullRequestNoBodySb sends a request with no body and stores the text response body in a
// StringBuilder.
StringBuilder sbResponse = new StringBuilder();
String responseText;
try {
rest.fullRequestNoBodySb("GET", "/api/items/123", sbResponse);
responseText = sbResponse.getAsString();
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println(responseText);
}
}