Skip to content

Fichtner21/Web-Info-API-with-Auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

How to connect to value from Custom Endpoint to show values from website

1. Using curl

	$request_url = 'http://{address_to_your_website}/wp-json/website_info/v1/website-details/';
	$credentials = array();
	$credentials = array('username: {username}', 'password: {password}');

	$curl_handle = curl_init( );
	curl_setopt( $curl_handle, CURLOPT_URL, $request_url );
	curl_setopt( $curl_handle, CURLOPT_CONNECTTIMEOUT, 0 );
	curl_setopt( $curl_handle, CURLOPT_TIMEOUT, 15 );
	curl_setopt( $curl_handle, CURLOPT_HTTPHEADER, $credentials  );
	curl_setopt( $curl_handle, CURLOPT_RETURNTRANSFER, TRUE );

	$JsonResponse = curl_exec( $curl_handle );
	$http_code = curl_getinfo( $curl_handle );

	if ( 200 == $http_code[ 'http_code' ] ) {
		echo  '<h2>'.get_bloginfo() .'</h2>' . '<br>';
		echo $JsonResponse;
	} else {
		echo 'ERROR: <pre>', var_export( $JsonResponse, true ), "</pre>\n";
	}

Replace: {address_to_your_website} i.e website.com. {username} i.e 'username123' must be string. {password} i.e 'password123' must be string.

2. Using Postman directly to API address.

alt text

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages