2013-01-18 67 views
2

我想在ColdFusion中重新創建一個PHP函數(因爲我不知道PHP),並認爲我的大部分函數並不是太糟糕,但在處理PHP中的cURL函數時遇到問題。ColdFusion替代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功能是我最好的盟友,但真的不知道如何處理的重碼。任何人都可以指出我正確的方向嗎?

回答

12

你說得對,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

+3

小尖和珍聞,如果你是從你的CFHTTP呼叫接收JSON,你會想使用#resultName.fileContent.toString(「utf-8」)#。另外,如果您要提供返回到前端的JSON,則需要確保適當地設置內容 - 同時使用類型和字符集

+0

謝謝你的工作。只需要處理如何讓身份驗證通過並立即開始工作! – CPB07

+2

cfhttp支持http基本身份驗證的用戶名和密碼屬性,因此在這方面您可能會確定。如果你正在嘗試使用其他方案,我相信會相當困難。 – barnyr