Android™
Android™
HTTP Response Inspection
See more HTTP Examples
Demonstrates how to inspect the HTTP response, including the status code, status text, and response headers, for Chilkat methods that don't use anHttpResponse object.
Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CkHttp http = new CkHttp();
// Returns the contents of the response body.
String jsonText = http.quickGetStr("https://chilkatsoft.com/helloWorld.json");
// Examine the response status code.
Log.i(TAG, "response status code: " + String.valueOf(http.get_LastStatus()));
// Examine the response status text
Log.i(TAG, "response status text: " + http.lastStatusText());
// Examine the full response header.
Log.i(TAG, "response header:");
Log.i(TAG, http.lastResponseHeader());
Log.i(TAG, "----");
// Examine the response content-type
Log.i(TAG, "LastContentType = " + http.lastContentType());
// Examine the response last-mod date
Log.i(TAG, "LastModDate = " + http.lastModDate());
// Load the response header into a Chilkat MIME object to access its fields individually.
CkMime mime = new CkMime();
mime.LoadMime(http.lastResponseHeader());
int numHeaders = mime.get_NumHeaderFields();
int i = 0;
Log.i(TAG, "---- MIME Headers ----");
while (i < numHeaders) {
Log.i(TAG, "name: " + mime.getHeaderFieldName(i));
Log.i(TAG, "value: " + mime.getHeaderFieldValue(i));
i = i + 1;
}
Log.i(TAG, "----");
// Get a header field value by name:
Log.i(TAG, "ETag: " + mime.getHeaderField("ETag"));
// Output:
// response status code: 200
// response status text: OK
// response header:
// Content-Type: application/json
// Last-Modified: Sun, 20 Aug 2023 11:36:27 GMT
// Accept-Ranges: bytes
// ETag: "34c27f8e5ad3d91:0"
// Server: Microsoft-IIS/10.0
// X-Powered-By: ASP.NET
// Date: Sat, 30 Aug 2025 14:38:13 GMT
// Content-Length: 22
// ----
// LastContentType = application/json
// LastModDate = 2023-08-20
// ---- MIME Headers ----
// name: Content-Type
// value: application/json
// name: Last-Modified
// value: Sun, 20 Aug 2023 11:36:27 GMT
// name: Accept-Ranges
// value: bytes
// name: ETag
// value: "34c27f8e5ad3d91:0"
// name: Server
// value: Microsoft-IIS/10.0
// name: X-Powered-By
// value: ASP.NET
// name: Date
// value: Sat, 30 Aug 2025 14:38:13 GMT
// name: Content-Length
// value: 22
// ----
// ETag: "34c27f8e5ad3d91:0"
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}