1. 程式人生 > >ruby on rails模擬HTTP請求錯誤發生:end of file reached

ruby on rails模擬HTTP請求錯誤發生:end of file reached

ats ace post result tcs 後來 nec scu microsoft

在文章 Ruby On Rails中REST API使用演示樣例——基於雲平臺+雲服務打造自己的在線翻譯工具 中,利用ruby的Net::HTTP發起http請求訪問IBM Bluemix上的

source=en&target=es&text=hello" style="color: rgb(51, 102, 153); text-decoration: none; font-family: Arial; font-size: 14px; line-height: 26px;">語言翻譯服務時,提示: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

ruby on rails模擬HTTP請求錯誤發生:end of file reached