Pat is correct the REST API is the best way to add a new post/page to your site. Here is a more complete guide with an example: https://rudrastyh.com/wordpress/rest-api-create-delete-posts.html#create_post
Example code for publishing a new post:
$api_response = wp_remote_post( 'https://WEBSITE/wp-json/wp/v2/posts', array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'LOGIN:PASSWORD' )
),
'body' => array(
'title' => 'My test',
'status' => 'draft', // ok, we do not want to publish it immediately
'content' => 'lalala',
'categories' => 5, // category ID
'tags' => '1,4,23' // string, comma separated
'date' => '2015-05-05T10:00:00', // YYYY-MM-DDTHH:MM:SS
'excerpt' => 'Read this awesome post',
'password' => '12$45',
'slug' => 'new-test-post' // part of the URL usually
// more body params are here:
// developer.wordpress.org/rest-api/reference/posts/#create-a-post
)
) );
$body = json_decode( $api_response['body'] );
// If the post was published successfully we can display a little message
if( wp_remote_retrieve_response_message( $api_response ) === 'Created' ) {
echo 'The post ' . $body->title->rendered . ' has been created successfully';
}
As you can see you simply pass on the data for for post via the body argument.
Authorization:
Login:PASSWORD on line 3 is the pair of username and password of a website user that has post publishing capabilities. A better method for Authorization may be to use the Application Passwords plugin and setup tokens. You can find the plugin here: https://wordpress.org/plugins/application-passwords/