Skip to content

XML-RPC server accepts POST requests only #49

@sanasar-dev

Description

@sanasar-dev

In my Laravel project, I want to publish content to WordPress blog. Everything works very well except for uploading media files. When I upload the file up to 850 KB, the file uploaded successfully. But when the file size exceeds 850 KB I get this error message XML-RPC server accepts POST requests only. And in my opinion this is unthinkable because I am using the same function to upload a file and the request method is always POST. This is my code.

$endpoint = $item->wp_url . '/xmlrpc.php';
$wpUser = $item->wp_username;
$wpPass = $item->wp_password;
$wpClient = new \HieuLe\WordpressXmlrpcClient\WordpressClient();
$wpClient->setCredentials($endpoint, $wpUser, $wpPass);

ob_clean();
$headers = get_headers($file->refe_file_path, TRUE);
$mimType = $headers['Content-Type'];
$output = '';

$handle = fopen($file->s3_file_path, 'r');

if ($handle) {
    while (!feof($handle)) {
        $output .= fread($handle, 1048576);
    }

    fclose($handle);
}

$uploadMedia = $wpClient->uploadFile($file->real_file_name, $mimType, $output, false);
$attachmentId = $uploadMedia['attachment_id'];

$content = [
    'post_type' => 'post',
    'post_status' => $request->input('post_status'),
    'post_title' => $title,
    'post_excerpt' => $request->input('post_excerpt'),
    'post_content' => $request->input('post_content'),
    'post_format' => $request->input('post_format'),
    'post_thumbnail' => $attachmentId,
    'terms_names' => [
          'category' => $request->input('post_category'),
           'post_tag' => $request->input('post_tags'),
    ],
    'post_author' => $request->input('post_author'),
];```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions