Android™
Android™
Get Response Header for Method that does not Return HttpResponse Object
Demonstrates how to get the response header and individual response header fields for a method that does not return an HTTP response object. (If a method returns an HHTTP response object, then the response header information should be obtained from the response 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);
boolean success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http = new CkHttp();
String strHtml = http.quickGetStr("https://www.duckduckgo.com/");
if (http.get_LastMethodSuccess() == false) {
Log.i(TAG, http.lastErrorText());
return;
}
Log.i(TAG, http.lastResponseHeader());
// Here's a sample HTTP response header:
// Server: nginx
// Date: Wed, 30 Sep 2020 13:13:02 GMT
// Content-Type: text/html; charset=UTF-8
// Transfer-Encoding: chunked
// Connection: keep-alive
// Vary: Accept-Encoding
// ETag: W/"5f7371f4-1683"
// Strict-Transport-Security: max-age=31536000
// X-Frame-Options: SAMEORIGIN
// Content-Security-Policy: default-src https: blob: data: 'unsafe-inline' 'unsafe-eval'; frame-ancestors 'self'
// X-XSS-Protection: 1;mode=block
// X-Content-Type-Options: nosniff
// Referrer-Policy: origin
// Expect-CT: max-age=0
// Expires: Wed, 30 Sep 2020 13:13:01 GMT
// Cache-Control: no-cache
// Content-Encoding: gzip
// We can load it into a Chilkat MIME object to get header field values:
CkMime mime = new CkMime();
success = mime.LoadMime(http.lastResponseHeader());
if (success == false) {
Log.i(TAG, mime.lastErrorText());
return;
}
// Get MIME header field values using Chilkat MIME...
Log.i(TAG, "----");
Log.i(TAG, "ETag: " + mime.getHeaderField("ETag"));
}
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."
}
}