Java
Chilkat2 Java
Inspect HTTP Request Header
Demonstrates theLastHeader property.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
public class ChilkatExample {
public static void main(String[] args) {
Http http = new Http();
String url = "https://chilkatsoft.com/echo_request_body.asp";
String json = "{\"greeting\":\"Hello World\"}";
// Send a POST with the JSON in the HTTP request body.
HttpResponse resp = new HttpResponse();
try {
http.httpStr("POST", url, json, "utf-8", "application/json", resp);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Examine the HTTP request header we just sent.
System.out.println(http.getLastHeader());
// Output:
// POST /echo_request_body.asp HTTP/1.1
// Host: chilkatsoft.com
// Accept: */*
// Accept-Encoding: gzip
// Content-Type: application/json
// Content-Length: 26
}
}