使用ruby Net:HTTP API将文件上传到远程apache服务器,失败并发生409冲突 [英] Uploading a file using ruby Net:HTTP API to a remote apache server failing with 409 Conflict

查看:288
本文介绍了使用ruby Net:HTTP API将文件上传到远程apache服务器,失败并发生409冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个程序,用于将文件从本地文件系统上载到远程Apache服务器.

Below is a program to upload a file from local file system to a remote Apache server.

程序以409冲突错误结束.有什么建议我在做什么错?我在httpd.conf中打开了DAV并提供了所有必要的权限,但是我仍然没有运气.我可以在需要时发布httpd.conf.

The program ends with a 409 conflict error. Is there any advice what am I doing wrong? I turned DAV on in httpd.conf and gave all necessary permissions, but I still had no luck. I can post the httpd.conf should it be needed.

这是代码:

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 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"]}

推荐答案

当我将第5行更改为此时,问题已解决:

The problem was resolved when I changed line 5 to this:

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

错误无法将其放入集合"表示无法对文件夹进行上载.必须指定文件名.

The error "cannot PUT to a collection" means, an upload cannot be done against a folder. A file name must be specified.

这篇关于使用ruby Net:HTTP API将文件上传到远程apache服务器,失败并发生409冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆