Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将php curl_setopt翻译成ruby等价物?_Php_Ruby_Curl_Translate - Fatal编程技术网

如何将php curl_setopt翻译成ruby等价物?

如何将php curl_setopt翻译成ruby等价物?,php,ruby,curl,translate,Php,Ruby,Curl,Translate,我需要一些帮助将php脚本翻译成ruby php脚本: $apiUrl = 'http://someurl/' . $_POST['type']; unset($_POST['type']); $fields = $_POST; $fields['ip'] = $_SERVER['REMOTE_ADDR']; $fieldsString = http_build_query($fields); $ch = curl_init(); ////set the url, number of PO

我需要一些帮助将php脚本翻译成ruby

php脚本:

$apiUrl = 'http://someurl/' . $_POST['type'];
unset($_POST['type']);

$fields = $_POST;
$fields['ip'] = $_SERVER['REMOTE_ADDR'];
$fieldsString = http_build_query($fields);

$ch = curl_init();

////set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Api-Key: somekey'
));
curl_setopt($ch,CURLOPT_URL, $apiUrl);
curl_setopt($ch,CURLOPT_POST, count($fieldsString));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fieldsString);
echo "<pre>";
var_dump($fields);
////execute post
$result = curl_exec($ch);
////close connection
curl_close($ch);
exit;
因此,问题是:

  • 我如何翻译#curl_setopt($ch,CURLOPT_POST,count($fieldsString))
  • 如何翻译#curl_setopt($ch,CURLOPT_HEADER,true)
  • easy.http_post会执行我想要的吗?即使用给定的标题选项发布参数,等等
  • 还有其他建议吗
多谢各位

如何翻译#curl_setopt($ch,CURLOPT_HEADER,true)

像这样:

curl_setopt($ch,CURLOPT_POST, FALSE);
我如何翻译35; curl_setopt($ch,CURLOPT_POST, 计数($fieldsString))

php curl_setopt()文档说:

CURLOPT_HTTPGET TRUE

重置HTTP请求方法以获取。由于GET是默认值, 仅当请求方法已更改时,才需要执行此操作

换句话说,如果你写:

http_method = (postparams.length==0) ? 'get' : 'post'
easy.http(http_method)
该请求默认为get请求。所以

curl_setopt($ch,CURLOPT_POST, FALSE);
http_method = (postparams.length==0) ? 'get' : 'post'
easy.http(http_method)