wordpress wp_remote_post从另一个wordpress网站获取响应

Everyone, I am New for Wordpress Development I develop one plugin there is two Wordpress site. site 1 sends the request to site 2. And site 2 will send some response for site 1 requests

site 1 index.php look like

$url = 'http://localhost/wordpress1/';
    $get_post_id = $commentdata['comment_details']['comment_post_ID'];
    $response = wp_remote_post( $url, array(
    'method' => 'POST',
    'timeout' => 45,
    'redirection' => 5,
    'httpversion' => '1.0',
    'blocking' => true,
    'headers' => array(),
    'body' => array('comment_details'=>$commentdata,'post_details'=>$post_details),
    'cookies' => array()
    ));
$response_data =  $response['body'];

site 2: index.php file looks like

$data = //some array data i will return
$sample =  serialize($data);

output: Its works good

my Requirement:

we have written the code both sites but t want to manage all those things in site 1 plugin code how to connect both code single plugin page(request and response handle in the single plugin)