将 PHP PUT HTTP 请求转换为 ColdFusion
这段代码在 ColdFusion 中会是什么样子?
protected function httpPut($url, $params = null, $data = null)
{
$fh = fopen('php://memory', 'rw');
fwrite($fh, $data);
rewind($fh);
$ch = curl_init($url);
$this->addOAuthHeaders($ch, $url, $params['oauth']);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_INFILE, $fh);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resp = $this->curl->addCurl($ch);
fclose($fh);
return $resp;
}
我有类似以下的内容,但它似乎不起作用。
<cffile action="write" file="d:\my\directory\path\test.xml" output="#arguments.requestXML#">
<cfhttp url="#oaAccessTokenURL#" method="#arguments.requestType#" charset="UTF-8">
<cfheader name="Authorization" value="#oauthheader#">
<cfhttpparam type="file" name="Course" file="d:\my\directory\path\test.xml">
</cfhttp>
我对 PHP 的了解不够,无法理解 $data 变量(只是一串 XML 数据)如何放入 http 请求中以及如何在 ColdFusion 中复制它。
What would this code look like in ColdFusion?
protected function httpPut($url, $params = null, $data = null)
{
$fh = fopen('php://memory', 'rw');
fwrite($fh, $data);
rewind($fh);
$ch = curl_init($url);
$this->addOAuthHeaders($ch, $url, $params['oauth']);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_INFILE, $fh);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resp = $this->curl->addCurl($ch);
fclose($fh);
return $resp;
}
I have something like the following, but it doesn't seem to be working.
<cffile action="write" file="d:\my\directory\path\test.xml" output="#arguments.requestXML#">
<cfhttp url="#oaAccessTokenURL#" method="#arguments.requestType#" charset="UTF-8">
<cfheader name="Authorization" value="#oauthheader#">
<cfhttpparam type="file" name="Course" file="d:\my\directory\path\test.xml">
</cfhttp>
I don't know enough about PHP to understand how the $data variable (which is just a string of XML data) is getting put into the http request and how to duplicate that in ColdFusion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会尝试将 method="put" 添加到您的 cfhttp 调用中。这将使 CFHTTP 发送正确的 http 动词(在本例中为 PUT)。
I would try adding method="put" to your cfhttp call. That will make CFHTTP send the correct http verb (PUT in this case).
这是 Java Spark(来自 Java 文档),您需要解决它:
在 CF 中翻译如下:
等等...
在我上面粘贴的链接中,您可以看到类似这样的内容:
Findworking Java soution and translate it in CF 。
编辑:
请参阅下面的评论以获取解决方案。
Here's Java spark (from Java docs), you need to work it out:
is translated in CF like this:
And so on...
In link I pasted above you can see somehting like this:
Find working Java soution and translate it in CF.
EDIT:
See comments below for a solution.
假设您正在执行 PUT 方法,则可以使用 ColdFusion 的 GetHttpRequestData() 函数来获取 XHR 数据。
然后您可以通过执行以下操作将其保存:
Assuming you are doing a PUT method, you can use ColdFusion's GetHttpRequestData() function to obtain the XHR data.
You can then save it out by doing something like this: