最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - wp_remote_post empty $_POST

programmeradmin0浏览0评论

Ok, I've searched a lot but cannot understand what I'm missing. I need to post some data to a php file on another server, but if I print the wp_remote_post variable I get:

{"headers":{},"body":"","response":{"code":200,"message":"OK"} .....

here the code:

        $url  = '.php';
    $args = array(
            'method'      => 'POST',
            'timeout'     => 45,
            'sslverify'   => false,
            'headers'     => array(
                    'Authorization' => 'xxxx',
                    'Content-Type'  => 'application/json; charset=utf-8',
            ),
            'body'        => json_encode($attachment_fields),
            'data_format' => 'body'
    );
    $request = wp_remote_post( $url, $args );

and $attachment_fields is an array built previously.

It seems that it sends it out (it says code 200) but in the php file the $_REQUEST (or $_POST) is empty... Sorry if is a stupid question but I'm struggling on it for a while..

Ok, I've searched a lot but cannot understand what I'm missing. I need to post some data to a php file on another server, but if I print the wp_remote_post variable I get:

{"headers":{},"body":"","response":{"code":200,"message":"OK"} .....

here the code:

        $url  = 'https://xxx.domain/api/api.php';
    $args = array(
            'method'      => 'POST',
            'timeout'     => 45,
            'sslverify'   => false,
            'headers'     => array(
                    'Authorization' => 'xxxx',
                    'Content-Type'  => 'application/json; charset=utf-8',
            ),
            'body'        => json_encode($attachment_fields),
            'data_format' => 'body'
    );
    $request = wp_remote_post( $url, $args );

and $attachment_fields is an array built previously.

It seems that it sends it out (it says code 200) but in the php file the $_REQUEST (or $_POST) is empty... Sorry if is a stupid question but I'm struggling on it for a while..

Share Improve this question edited Jan 28, 2021 at 20:04 Dany92 asked Jan 28, 2021 at 19:05 Dany92Dany92 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Ok, found the problem: I didn't have to json_encode the body.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论