Cómo agregar encabezados de solicitud en llamadas API remotas de WordPress

28 nov 2015, 12:30:59
Vistas: 16.9K
Votos: 8

Hola, soy nuevo en desarrollo para WordPress. ¿Alguien puede decirme cómo agregar encabezados de solicitud en las llamadas API remotas wp_remote_get() o wp_remote_post()?

Intenté lo siguiente pero no funcionó:

    $response = wp_remote_get( add_query_arg( array(
        'Affiliate-Id' => XXXXX,
        'Affiliate-Token'     => XXXXX
    ), $api_url ) , array( 'timeout' => 10));
0
Todas las respuestas a la pregunta 1
0
23

Si deseas enviar Affiliate-Id y Affiliate-Token en los encabezados, necesitas pasarlos en los argumentos opcionales de la función wp_remote_get.

Ejemplo:

$response = wp_remote_get( $api_url , array( 
    'timeout' => 10,
    'headers' => array( 
        'Affiliate-Id' => XXXXX,
        'Affiliate-Token'=> XXXXX 
    ) 
));
28 nov 2015 13:05:04