使用 wp_remote_post 设置内容类型 [英] Set the content-type with wp_remote_post

查看:27
本文介绍了使用 wp_remote_post 设置内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用函数 wp_remote_post 时,如何将 content-type 字段设置为我的 HTTP 请求标头中的 application/json ?

How can I set the content-type field to application/json in the header of my HTTP request when using the function wp_remote_post ?

推荐答案

检查 的文档wp_remote_post 这会给你一些关于你可以用远程请求做什么的额外信息.

Check the documentation for wp_remote_post which will give you some extra information on what you can do with the remote request.

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

When you make the request using that function, you can set headers in the second parameter ($args) within an array. For example:

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

$request = wp_remote_post( $url, $args );

这篇关于使用 wp_remote_post 设置内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆