I used wp-cli to import media from another site. wp import always complained Failed to import Media xxxx: Request failed due to an error: A valid URL was not provided. (http_request_failed) and imported nothing.
I enabled debug by adding define( 'IMPORT_DEBUG', true ); into wp-config.php and traced import call into deep. Here is the result:
#0 wp_validate_redirect / wp-includes/http.php:620 #1 allowed_http_request_hosts / wp-includes/class-wp-hook.php:294 #2 WP_Hook->apply_filters / wp-includes/plugin.php:212 #3 apply_filters / wp-includes/http.php:581 #4 wp_http_validate_url / wp-includes/class-http.php:270 #5 WP_Http->request / wp-includes/class-http.php:635 #6 WP_Http->get / wp-includes/http.php:68 #7 wp_safe_remote_get / wp-content/plugins/wordpress-importer/class-wp-import.php:1008 #8 WP_Import->fetch_remote_file / wp-content/plugins/wordpress-importer/class-wp-import.php:954 #9 WP_Import->process_attachment / wp-content/plugins/wordpress-importer/class-wp-import.php:697 #10 WP_Import->process_posts / wp-content/plugins/wordpress-importer/class-wp-import.php:88 #11 WP_Import->import / phar:.../Import_Command.php:179 #12 Import_Command->import_wxr / phar:.../Import_Command.php:81
Solution 1
Add following lines into wp-content/themes/{your theme}/functions.php:
add_filter("http_request_host_is_external", function($allow, $host, $url){ if (gethostbyname($host) == "your_hostname.com") { $allow = true; } return $allow; }, 10, 3);
It enables HTTP request to original site.
Solution 2
Admin panel / Settings / General / Site Address (URL) - here put URL of the original site. Or use wp-cli:
wp option update home your_hostname.com
IMPORT_DEBUGand set it totrueto get meaningful feedback instead of just "Failed to import media". I can't imagine why this isn't default behavior. That may help narrow your problem down if the weather is just right.IMPORT_DEBUGoptiondefine ( 'IMPORT_DEBUG', true );.xmlURLs are onhttps, editing thexmlfiles to togglehttpstohttphelped.