使用 wp_remote_post 设置内容类型

2 php wordpress

使用该函数时,如何将content-type字段设置为application/jsonHTTP 请求的标头wp_remote_post

小智 6

查看文档,wp_remote_post该文档将为您提供有关远程请求可以做什么的一些额外信息。

当您使用该函数发出请求时,您可以$args在数组的第二个参数 ( ) 中设置标头。例如:

$args = array(
    'headers' => array(
        'content-type' => 'application/json'
    ),
);

$request = wp_remote_post( $url, $args );
Run Code Online (Sandbox Code Playgroud)