目录
PHP to Ruby Code
Jun 06, 2016 pm 08:50 PM
php
ruby
和下面这段代码相同的ruby 怎么写呢?
public function makeRequest($url, $method, $postfields = NULL) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); if ('POST' === $method) { curl_setopt($ch, CURLOPT_POST, 1); if (!empty($postfields)) { curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); } } curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->_connectTimeOut); curl_setopt($ch, CURLOPT_TIMEOUT, $this->_timeOut); curl_setopt($ch, CURLOPT_USERAGENT, $this->_userAgent); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $output = curl_exec($ch); curl_close($ch); return $output; }
登录后复制
登录后复制
THK
回复内容:
和下面这段代码相同的ruby 怎么写呢?
public function makeRequest($url, $method, $postfields = NULL) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); if ('POST' === $method) { curl_setopt($ch, CURLOPT_POST, 1); if (!empty($postfields)) { curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); } } curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->_connectTimeOut); curl_setopt($ch, CURLOPT_TIMEOUT, $this->_timeOut); curl_setopt($ch, CURLOPT_USERAGENT, $this->_userAgent); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $output = curl_exec($ch); curl_close($ch); return $output; }
登录后复制
登录后复制
THK
require 'uri' require 'net/http' require 'openssl' def makeRequest(url, method, postfields="", isHttps=false) httpHeader = { "Expect:"=>"" } uri = URI(url) response = nil http = Net::HTTP.new(uri.host, uri.port) if isHttps http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end http.start() response = http.send_request(method, uri.path, postfields, httpHeader) ret_code = response.code; ret_str = response.body; return ret_str; end
登录后复制
推荐一个不同编程语言之间转换的项目矩阵,楼主可以看看
http://langlangmatrix.com/
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章
击败分裂小说需要多长时间?
3 周前
By DDD
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前
By 尊渡假赌尊渡假赌尊渡假赌
公众号网页更新缓存难题:如何避免版本更新后旧缓存影响用户体验?
3 周前
By 王林

热门文章
击败分裂小说需要多长时间?
3 周前
By DDD
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前
By 尊渡假赌尊渡假赌尊渡假赌
公众号网页更新缓存难题:如何避免版本更新后旧缓存影响用户体验?
3 周前
By 王林

热门文章标签

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南

如何设置 Visual Studio Code (VS Code) 进行 PHP 开发
