Java
Chilkat2 Java
Setting a HTTP Max Response Size
Demonstrates theMaxResponseSize property.
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();
long maxSz = 16384;
http.setMaxResponseSize(maxSz);
// Try to get something larger, such as hamlet.xml which is 279658 bytes
String xmlStr;
try {
xmlStr = http.quickGetStr("https://chilkatsoft.com/hamlet.xml");
} catch (ChilkatException e) {
// If the LastErrorText contains the string "MaxResponseSize",
// then the HTTP request failed because the response body would've been larger than the max allowed response size.
System.out.println(e.getLastErrorText());
return;
}
System.out.println("OK");
}
}