Sample code for 30+ languages & platforms
React Native

POST application/x-www-form-urlencoded using REST API

See more REST Examples

Demonstrates how to send a POST with query params (x-www-form-urlencoded) using the Chilkat REST object.

Chilkat React Native Downloads

React Native
import { Rest } 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 rest = new Rest();

  // This example will send to https://www.chilkatsoft.com/echoPost.asp

  // Make the initial connection (without sending a request yet).
  const bTls = true;
  const port = 443;
  const bAutoReconnect = true;
  try {
    await rest.connectAsync('www.chilkatsoft.com', port, bTls, bAutoReconnect);
  } catch {
    console.log(rest.lastErrorText);
    return;
  }

  // Provide query params.
  rest.addQueryParam('firstName', 'John');
  rest.addQueryParam('lastName', 'Doe');
  rest.addQueryParam('company', 'Bisco Bits Ltd.');

  let responseStr: string;
  try {
    responseStr = await rest.fullRequestFormUrlEncodedAsync('POST', '/echoPost.asp');
  } catch {
    console.log(rest.lastErrorText);
    return;
  }

  // When successful, the response status code will equal 200.
  if (rest.responseStatusCode !== 200) {
    // Examine the request/response to see what happened.
    console.log(`response status code = ${rest.responseStatusCode}`);
    console.log(`response status text = ${rest.responseStatusText}`);
    console.log(`response header: ${rest.responseHeader}`);
    console.log(`response body (if any): ${responseStr}`);
    console.log('---');
    console.log(`LastRequestStartLine: ${rest.lastRequestStartLine}`);
    console.log(`LastRequestHeader: ${rest.lastRequestHeader}`);
    return;
  }

  console.log(responseStr);
  console.log('Success.');
}