2012-08-23 78 views
2

下面是一個從本地文件系統上傳文件到遠程Apache服務器的程序。使用ruby上傳文件net:HTTP API到遠程apache服務器失敗409 Conflict

程序以409衝突錯誤結束。有什麼建議我做錯了什麼?我在httpd.conf中打開了DAV並給了所有必要的權限,但我仍然沒有運氣。如果需要,我可以發佈httpd.conf。

這是代碼:

BOUNDARY = "AaB03xZZZZZZ11322321111XSDW" 
uri = URI.parse("http://localhost/dropbox/") 
file = "/tmp/KEYS.txt" 
http = Net::HTTP.new(uri.host, uri.port) 
request = Net::HTTP::Put.new(uri.request_uri) 
request.body_stream=File.open(file) 
request["Content-Type"] = "multipart/form-data" 
request.add_field('Content-Length', File.size(file)) 
request.add_field('session', BOUNDARY) 
response=http.request(request) 
puts "Request Headers: #{request.to_hash.inspect}" 
puts "Sending PUT #{uri.request_uri} to #{uri.host}:#{uri.port}" 
puts "Response #{response.code} #{response.message}" 
puts "#{response.body}" 
puts "Headers: #{response.to_hash.inspect}" 

,其輸出:

request = Net::HTTP::Put.new("#{uri.request_uri}/test.file") 

錯誤「不能:

Request Headers: {"accept"=>["*/*"], "host"=>["localhost"], "content-length"=>[88873],  "content-type"=>["multipart/form-data"], "session"=>["AaB03xZZZZZZ11322321111XSDW"], "connection"=>["close"]} 
Sending PUT /dropbox/ to localhost:80 
Response 409 Conflict 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>409 Conflict</title> 
</head><body> 
<h1>Conflict</h1> 
<p>Cannot PUT to a collection.</p> 
<hr /> 
<address>Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.10 with Suhosin-Patch Server at localhost Port 80</address> 
</body></html> 
Headers: {"server"=>["Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.10 with Suhosin-Patch"], "content-length"=>["315"], "content-type"=>["text/html; charset=ISO-8859-1"], "date"=>["Thu, 23 Aug 2012 17:36:40 GMT"], "connection"=>["close"]} 

回答

4

當我改變行5這個問題得到解決PUT到集合「意味着,無法對文件夾進行上傳。文件名必須指定。

相關問題