Previously I am using the below code. Now I need to change this code and replace file_get_contents()
with wp_safe_remote_get()
. I need to know how to set 'header' => "Accept: application/json"
in wp_safe_remote_get()
:
$opts = array(
'http' => array(
'method' => "GET",
'header' => "Content-Type:application/json",
'header' => "Accept: application/json"
)
);
$context = stream_context_create($opts);
$file = file_get_contents(
'http://xxxxxxxx.xxxx/xapix/xjson/xxxxx.php',
false,
$context
);
I have tried to do this but not working
$args = array( 'timeout' => 30 , 'header' => "Accept: application/json");
$file = wp_safe_remote_get('http://xxxxxxxx.xxxx/xapix/xjson/xxxxx.php', $args);