coldfusion cfhttp to PHP

I've designed a website Im running for a sports team I coach in Wordpress (more specifically PHP). For the past few years we have used an online web service that runs a stats based program in Coldfusion. They recently opened up a feed so users can use there own customized websites with their data implemented in it.

They provided me with a feed like so (not going to provide my details for security reasons):

<cfhttp url="http://datafeed" method="post" result="result">
            <cfhttpparam type="formfield" name="seasonID" value="29725">
            <cfhttpparam type="formfield" name="codekey" value="mycodekey">
<cfhttpparam type="formfield" name="showGameType" value="RS">
</cfhttp>

I have no experience with Coldfusion what so ever and I've tried to do some reading about using this in a PHP environment but everything I tend to find is PHP to Coldfusion, not the opposite.

Because of this I come to stack, Im not entirely sure how this would work within PHP but would cURL be the answer? Ideally Id like to just create a couple wordpress functions and call them on my template pages.


The code example you have there is a simple form style http post with the response from the post being written to the variable "result".

The form post contains three fields; "seasonid", "codekey" and "showgametype".

To be honest I have no clue how you would write it in PHP, cURL is the library you will need to use. The examples in the comments on the main cURL page look to do what you would need; capture the http response from a post or get to a URL.

Hopefully my description of what the example code is doing will help you determine your course.


Thanks all for the help managed to figure this out with some hints provided above.

The datafeed where I was accessing the information needed the codekey obviously which I wasnt sure how to figure out but managed to get it, this is what I used, not 100% sure if its right but Ive managed to retrieve the data which ended up being in JSON format.

If there are any tips to this solution Im all ears..

function name() {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://urlhere.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, false);

$data = array(
    'codekey' => 'mycodekey'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$rawdata = curl_exec($ch);
curl_close($ch);

//Convert Returned JSON data to PHP Object
$output = (json_decode($rawdata));


foreach($output->DATA as $key => $val) {
    echo "<br />" . $val[1];
}

This was a little different then my example above as I decided to use an easier feed that just had the seasons because the JSON data returned in my feed above had a lot more data (GP, Wins, Losses, Ties, PTS,) etc.

链接地址: http://www.djcxy.com/p/31196.html

上一篇: ColdFusion ...在CFLOOP内部进行CFHTTP调用

下一篇: coldfusion cfhttp到PHP