ColdFusion替代cURL

CPB*_*B07 2 php cookies coldfusion curl cfhttp

我正在尝试在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);
Run Code Online (Sandbox Code Playgroud)

我假设CFHTTP功能是我最好的盟友,但不确定如何处理重新编码.有人能指出我正确的方向吗?

bar*_*nyr 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# />
Run Code Online (Sandbox Code Playgroud)

这里记录了cfhttp标记:http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_g-h_09.html

  • 如果你从cfhttp调用中接收JSON,那么你需要使用#resultName.fileContent.toString("utf-8")#.此外,如果您将提供返回到前端的JSON,您将需要确保适当地设置内容 - 同时使用类型和字符集<cfcontent type ="application/json; charset = UTF-8"reset = "假"> (3认同)
  • cfhttp支持http基本身份验证的用户名和密码属性,因此您可以在这方面做得很好.如果你正在尝试使用其他方案,我相信会更加困难. (2认同)