和下面这段代码相同的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
推荐一个不同编程语言之间转换的项目矩阵,楼主可以看看
内容简介 《PHP编程(第3版)(影印版)》作者塔特罗等的诸多风格提示和实践编程建议将可以帮助你成为一名顶尖PHP程序员。 作者简介 作者:(美国)塔特罗(Tatroe K.) (加拿大)麦金太尔(MacIntyre P.) (丹麦)勒多夫(Ixrdorf R.)Foreword Preface 1. Introduction to PHP What Does PHP
633
立即学习“PHP免费学习笔记(深入)”;
http://langlangmatrix.com/
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号