如何将php curl_setopt翻译成ruby等价物?
我需要一些帮助将php脚本翻译成ruby php脚本:如何将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
$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_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)