首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在wordpress插件中使用php制作http请求?

如何在wordpress插件中使用php制作http请求?
EN

Stack Overflow用户
提问于 2021-02-27 20:08:53
回答 1查看 283关注 0票数 0

我想在wordpress插件中使用php发出http请求,这是我的代码

代码语言:javascript
复制
 $request = wp_remote_post('https://en0ctqi09fhu7m.x.pipedream.net/', array(
                'headers' => array('Accept' => 'application/json'),
                'body' => array('data_type' => 'customer', )
            ));

但在身体里我想发送这些数据

代码语言:javascript
复制
{
    "data_type:": "customer",
    "customer": {
        "id": 123,
        "first_name": "John",
        "last_name": "Doe",
        "email": "john@johndoe.com",
        "address": "18/XII, Light Avenue, Upper Manhattan, NY"
    }
}

我搞不懂如何在身体切片中发送数据

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-27 20:17:58

试试这个:

代码语言:javascript
复制
$response = wp_remote_post( $url, array(
    'method'      => 'POST',
    'headers' => array('Accept' => 'application/json'),
    'timeout'     => 45,
    'redirection' => 5,
    'httpversion' => '1.0',
    'blocking'    => true,
    'body'        => array(
        'data_type' => 'customer',
        'customer' => array(
            "id" => 123,
            "first_name" => "John",
            "last_name" => "Doe",
            "email" => "john@johndoe.com",
            "address" => "18/XII, Light Avenue, Upper Manhattan, NY"
        )
    )
));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66403051

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档