下面是一个将文件从本地文件系统上传到远程 Apache 服务器的程序。
程序以 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}"
Run Code Online (Sandbox Code Playgroud)
它的输出:
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> …Run Code Online (Sandbox Code Playgroud)