Sample code for 30+ languages & platforms
React Native

HTTP Basic Authentication Test

Demonstrates how to do HTTP basic authentication using Chilkat.

Chilkat React Native Downloads

React Native
import { Http } from '@chilkat/react-native'

async function chilkatExample() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const http = new Http();

  // To use HTTP Basic authentication:
  http.login = 'myLogin';
  http.password = 'myPassword';
  http.basicAuth = true;

  // Run the test using this URL with the credentials above.  
  // (Works while httpbin.org keeps the test endpoint available.)
  let jsonResponse: string;
  try {
    jsonResponse = await http.quickGetStrAsync('https://httpbin.org/basic-auth/myLogin/myPassword');
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  console.log(`Response status code: ${http.lastStatus}`);

  console.log(jsonResponse);

  // Output:

  // Response status code: 200
  // {
  //   "authenticated": true, 
  //   "user": "myLogin"
  // }
}