简体   繁体   中英

Post curl data with php

I have a dashboard which I post data to display on.The dashbaord has multiple segments. I have an sql query which retrieves the data and loops through to push results. I want run the curl command below via php within this script. Can someone point me in the right direction? Or help. I have looked around a bit but im confused on how to get it to work.

Below is the what my php page will generate and this is what i would like to send via php using curl.

    curl -d '{ "auth_token" : "YOUR_AUTH_TOKEN" , "value" : "519" }' http://172.21.4.62:3030/widgets/Skin

Try without any additional classes:

  $ch = curl_init('http://172.21.4.62:3030/widgets/Skin'); $curlOptions = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION] => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => array("auth_token" => "YOUR_AUTH_TOKEN", "value" => "519"), ); curl_setopt_array($ch, $curlOptions); $response = curl_exec($ch); curl_close($ch); 

Its easier to use any curl class, fe curl.class.php

Usage:

$curl = new Curl();

$data = array("auth_token" => "YOUR_AUTH_TOKEN", "value" => "519");

$page = $curl->post("YOUR_URL_TO_CALL_VIA_CURL", $data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM