• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP to Ruby Code

php 搞代码 4年前 (2022-01-25) 20次浏览 已收录 0个评论
文章目录[隐藏]

和下面这段代码相同的ruby 怎么写呢?

public function makeRequest($url, $method, $postfields = NULL) {        $ch = curl_init();        curl_setop<b style="color:transparent">(、本文来源gao@!dai!ma.com搞$$代^@码网*</b><i>搞gaodaima代码</i>t($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/


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP to Ruby Code
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址