IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]ruby on rails模拟HTTP请求发生错误:end of file reached

    testcs_dn发表于 2015-12-26 19:11:45
    love 0

    在文章 Ruby On Rails中REST API使用示例——基于云平台+云服务打造自己的在线翻译工具 中,利用ruby的Net::HTTP发起http请求访问IBM Bluemix上的语言翻译服务时,提示:end of file reached

    代码如下:

    auth = "c9819718-4660-441c-9df7-07398950ea44:qUvrJPqwsgOx";
    surl = "https://" + auth + "@gateway.watsonplatform.net/language-translation/api/v2/translate?source=en&target=es&text=" + @txt;
    uri = URI.parse(surl);
    
    begin #开始
    	http = Net::HTTP.new(uri.host, uri.port)
    	http.use_ssl = true
    	request = Net::HTTP::Get.new(uri.request_uri)
    	response = http.request(request)
    	@result = "{\"text\":\"#{response.body}\"}";
    rescue
    	@result = "{\"error\":\"#{$!}!\"}";
    end


    看到这种错误信息,刚开始以为 是语法的问题,但怎么也找不到问题;

    后来注意到,URL是HTTPS开头,想到可能是它的问题,

    经过搜索,果然是需要设置:http.use_ssl = true

    设置之后,又出来新的问题:SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed



沪ICP备19023445号-2号
友情链接