PHP code example of pronamic / wp-http

1. Go to this page and download the library: Download pronamic/wp-http library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pronamic / wp-http example snippets


$response = Http::request( $url, $args );

$data = $response->json();

$url = 'https://www.pronamic.nl/wp-json/wp/v2/types/post';

Http::fake( $url, __DIR__ . '/../http/pronamic-nl-wp-json-types-post.http' );

$response = \wp_remote_get( $url );

// or

$response = Http::get( $url );



namespace YourNamespace;

use Pronamic\WordPress\Http\Factory;

class YourTest extends \WP_UnitTestCase {
	/**
	 * Setup.
	 */
	public function setUp() {
		parent::setUp();

		$this->factory = new Factory();
	}

	/**
	 * Test request.
	 */
	public function test_request() {
		$this->factory->fake( 'http://example.com/', __DIR__ . '/../http/example-com.http' );

		$result = \wp_remote_get( 'http://example.com/' );

		// asserts
	}
}


Undefined offset: 2

wordpress/wp-ncludes/class-wp-hook.php:292
wordpress/wp-p:626
wordpress/wp-