Published on : August 04, 2020
Title : php.wp_remote_post
Purpose : Performs an HTTP request using the POST method and returns its response. Or in other words, we use it to call APIs.
Syntax : [php.wp_remote_post p1=’url’ p2=’array data’ o.set=variable name /]
Input Parameters :
p1 : (Required) URL to retrieve
p2 : (array) (Optional) Request arguments. Default value: array()
Return Value : It returns the response received from the URL
Example 1 :
Code :
[template.set_array config]
        [Content-Type _value=’application/json’ /]
[template.set_array post_data]
    [companyid _value=’U67100MH2016PTC280879′ /]
[template.get post_data json_encode=true o.set=template.post_data /]
[template.set data.body=”{template.post_data}” data.headers=”{template.config.header}” data.data_format=”body” data.timeout=”5000″/]
[php.wp_remote_post p1=”{template.config.url}” p2=”{}” o.set=template.result /]
[template.result.body.json_decode o.set=template.decoded_response /][template.decoded_response.dump /]
Output : “result” => string(7) “success”
“response” => array(3)
Description : We passed the URL from where we wanted to receive the response for mcaid we passed. And based on that we received the response from the URL in json which we decoded