簡體   English   中英

Webrick / Rails - 發送POST請求后出現超時錯誤

[英]Webrick/Rails - Timeout Error after sending POST request

我正在使用Redmine插件,我創建了一個方法,我發送2個HTTP POST請求將文件附加到文檔。

執行第一個請求后,雖然請求已成功完成,但我收到Timeout::Error (Timeout::Error) ,這是Webrick的錯誤代碼

Timeout::Error (Timeout::Error): 
/usr/local/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill' 
/usr/local/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill' 
/usr/local/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil' 
/usr/local/lib/ruby/1.9.1/net/protocol.rb:132:in `readline' 
/usr/local/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line' 
/usr/local/lib/ruby/1.9.1/net/http.rb:2551:in `read_new' 
/usr/local/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_request'  
/usr/local/lib/ruby/1.9.1/net/http.rb:1316:in `catch' 
/usr/local/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request' 
/usr/local/lib/ruby/1.9.1/net/http.rb:1293:in `request' rest-client (1.6.7) lib/restclient/net_http_ext.rb:51:in `request' 
/usr/local/lib/ruby/1.9.1/net/http.rb:1286:in `block in request' 
/usr/local/lib/ruby/1.9.1/net/http.rb:745:in `start' 
/usr/local/lib/ruby/1.9.1/net/http.rb:1284:in `request'
...
...
Started POST "/uploads.json?attachment_id=1&filename=testFile.txt" for <server_IP_address> at 2014-04-02 09:15:28 +0200 
Processing by AttachmentsController#upload as JSON 
Parameters: {"attachment_id"=>"1", "filename"=>"testFile.txt"} 
Current user: <user> (id=3) 
Saving attachment '/home/user/Redmine/redmine-2.4.2/files/2014/04/140402091528_testFile.txt' (72 bytes) 
Rendered attachments/upload.api.rsb (1.7ms) 
Completed 201 Created in 87.9ms (Views: 7.9ms | ActiveRecord: 11.4ms)

您可以看到我在響應中獲得201狀態,因此它可以工作,但是我有這個Timeout錯誤並且執行在那里停止。

這是我的代碼:

uri = URI.parse("http://<server_IP_address>:3000/uploads.json")

http = Net::HTTP.new(uri.host, uri.port)
@file = File.new("/home/testFile.txt")
@csrfToken = session[:_csrf_token]

request = Net::HTTP::Post.new(@uri.path+"?attachment_id=1&filename=testFile.txt", initheader = {'Content-Type' => "application/octet-stream", 'X-CSRF-Token' => @csrfToken, 'X-Redmine-API-Key' => "my_key"})
request.body = @file.read
@response = http.request(request)

@upToken = @response.body

@secondResponse = RestClient.post 'http://<server_IP_address>:3000/documents/150/add_attachment', {:multipart => true, :utf8 => "\u2713", :authenticity_token => @csrfToken, :attachment => { "1" => {:filename => "testFile.txt", :description => "Dropbox blabla", :token => @upToken}}, :commit => "Add"}, :'X-Redmine-API-Key' => "mykey"

我也嘗試過使用Apache Web服務器,第一個請求工作正常,我只能在Webrick服務器上運行Redmine時遇到此問題。

你知道這個錯誤來自哪里以及如何擺脫它?

您需要做的是您需要更改webrick服務器中的請求超時值,以便檢查此問題的答案: 如何在rails中設置請求超時(瘦或webrick服務器)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM