【问题标题】:ColdFusion alternative to cURLcURL 的 ColdFusion 替代品
【发布时间】:2013-01-18 12:41:56
【问题描述】:

我正在尝试在 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 函数是我最好的盟友,但我不确定如何处理重新编码。谁能指出我正确的方向吗?

【问题讨论】:

    标签: php cookies curl coldfusion cfhttp


    【解决方案1】:

    你是对的,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

    【讨论】:

    • 小提示和花絮,如果您从 cfhttp 调用接收 JSON,您将需要使用#resultName.fileContent.toString("utf-8")#。此外,如果您将提供返回到前端的 JSON,您将需要确保正确设置内容 - 使用 type 和 charset
    • 感谢工作。只需要研究如何让身份验证通过并立即工作!
    • cfhttp 支持用于 http 基本身份验证的用户名和密码属性,因此在这方面您可能没问题。如果您尝试使用其他方案,我相信会更加困难。
    • 我不知道其他人,但上面的例子是我喜欢 Coldfusion 的原因。它看起来比 PHP 干净得多。
    • @rob M:它看起来更干净,因为 curl 涵盖了除 http 和 https 之外的以下协议:http、https、ftp、gopher、telnet、dict、file 和 ldap 协议。 libcurl 还支持 HTTPS 证书、HTTP POST、HTTP PUT、FTP。这相当于使用 cfftp、cfldap、cfmail、cfpop、cfile 等。
    猜你喜欢
    • 2014-03-03
    • 1970-01-01
    • 2017-03-25
    • 2016-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-14
    相关资源
    最近更新 更多