im trying to get the xml but i always get a 403 error. But with postman its working fine.
i dont think i did something wrong with the authorization but maybe im wrong.
this code is in the functions.php and im calling it with https://localhost/wordpress/wp-admin/admin-ajax.php?action=nopriv_search_mobileads
add_action('wp_ajax_nopriv_search_mobileads', 'get_mobileads_from_api');
add_action('wp_ajax_search_mobileads', 'get_mobileads_from_api');
function get_mobileads_from_api() {
$url = ('https://services.mobile.de/search-api/search?');
$wp_request_headers = array(
'Host' => 'https://services.mobile.de',
'Accept' => 'application/xml',
'Authorization' => 'Basic '.base64_encode('id:pw')
);
$results = wp_remote_request(
$url,
array(
'method' => 'GET',
'headers' => $wp_request_headers
)
);
print_r($results);
}
output:
Array ( [headers] => Requests_Utility_CaseInsensitiveDictionary Object ( [data:protected] => Array ( ) ) [body] => [response] => Array ( [code] => 403 [message] => Forbidden ) [cookies] => Array ( ) [filename] => [http_response] => WP_HTTP_Requests_Response Object ( [response:protected] => Requests_Response Object ( [body] => [raw] => HTTP/1.1 403 [headers] => Requests_Response_Headers Object ( [data:protected] => Array ( ) ) [status_code] => 403 [protocol_version] => 1.1 [success] => [redirects] => 0 [url] => https://services.mobile.de/search-api/search? [history] => Array ( ) [cookies] => Requests_Cookie_Jar Object ( [cookies:protected] => Array ( ) ) ) [filename:protected] => [data] => [headers] => [status] => ) ) 0
2
Answers
found a way.
Unless the actual username is "id" and the actual password is "pw" that’s not going to work.