Question

I'm trying to re-create a PHP function in ColdFusion (as I don't know PHP) and think most of my function is not too bad but having issues when dealing with the cURL function in PHP.

The function code is

$cookie_string = $this->EASW_KEY."; ".$this->EASF_SESS ."; ".$this->PHISHKEY;
$ch = curl_init($search);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIE, $cookie_string);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'x-http-method-override: GET',
    $this->XSID)
);

//Contains the JSON file returned
$EAPSEARCH = curl_exec($ch);
curl_close($ch);

unset (List of variables);

I'm assuming the CFHTTP function is my best ally but not really sure how to deal with the re-code. Can anyone point me in the right direction please?

Était-ce utile?

La solution

You're right, CFHTTP is the way to go. Here's a version of your call above translated to a CFHTTP call:

<cfhttp url="http://some.server/path" method="POST" result="resultName>
  <cfhttpparam type="cookie" name="EASW_KEY" value="#EASW_VALUE#" />
  <cfhttpparam type="cookie" name="EASF_SESS" value="#EASF_SESS_VALUE#" />

  <cfhttpparam type="header" name="Content-Type" value="application/json" />
  <cfhttpparam type="header" name="x-http-method-override" value="GET" />

  <cfhttpparam type="body" value="#myJSONStringVariable#" />
</cfhttp>

<cfdump var="#resultName# />

The cfhttp tag is documented here: http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_g-h_09.html

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top