简体   繁体   中英

Get data from request URL

I'm trying to get data from a system through its own API. It's this one: https://www.zoho.com/recruit/get-records.html

So I'm really new to PHP, and all I can find is examples where they grab the variable name from the URL via the get method. Or with this API in particular, inserting data.

I'm trying to put the data from the request into an array, but all I get from the print is Array(). Am I going about this totally wrong? The API explains it really awfully, I think... and there's no example anywhere.

$url = "https://recruit.zoho.com/ats/private/xml/JobOpenings/getRecords?apikey=$api_key&ticket=$ticket_id";

$request = new WP_Http;
$result = $request->request($url, $data = array());
print_r($data);

Besides printing $data instead of $result there was nothing wrong. I contacted the company that hosts the data, and it was an issue on their end.

Try this code...

        $url = "https://recruit.zoho.com/ats/private/xml/JobOpenings/getRecords?apikey=$api_key&ticket=$ticket_id";
        $headers = "Content-Type: application/x-www-form-urlencoded \n  accesskey: abcdefghijklmnopqrstuvwx \n  outputtype: json";//or what ever is your content type);

        $request = new WP_Http;
        $result = $request->request( $url, array('headers' => $headers) );

        if ( !is_wp_error($result) ) {$body = json_decode($result, true);}

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