我正在尝试在 ColdFusion 中重新创建一个 PHP 函数(因为我不了解 PHP)并且认为我的大部分函数都还不错,但是在处理 PHP 中的 cURL 函数时遇到了问题。
函数代码为
$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);
我假设 CFHTTP 函数是我最好的盟友,但不确定如何处理重新编码。谁能指出我正确的方向?
最佳答案
你说得对,CFHTTP 是正确的选择。这是将上面的调用转换为 CFHTTP 调用的版本:
<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# />
cfhttp 标记记录在此处:http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_g-h_09.html
关于php - ColdFusion 替代 cURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14399220/