In order to post multipart/form-data, I’ve got to build data like:
Content-Type: multipart/form-data;
boundary=---------------------------12199339629315
Content-Length: 402
-----------------------------12199339629315
Content-Disposition: form-data; name="upfile"; filename="test.txt"
Content-Type: text/plain
[snip ... file data]
-----------------------------12199339629315--
I do this, then do the following with http.rb:
# data equals the above stuff
# @h is my http object
req = Net::HTTP::Post.new(get_url)
resp = @h.request(req, data)
In this case, http.rb seems to get in the way. Way down under the
@h.request call we come to this:
def send_request_with_body( sock, ver, path, body )
@header['content-length'] = body.length.to_s
@header.delete 'transfer-encoding'
unless @header['content-type']
$stderr.puts 'net/http: warning: Content-Type did not set; ...
[snip]
@header[‘content-type’] = 'application/x-www-form-urlencoded’
end
request sock, ver, path
sock.write body
end
So, now I’m sending the following packets to the web server:
POST /my.cgi.rb HTTP/1.1
Connection: close
Content-Type: application/x-www-form-urlencoded
Authorization: Basic cnNxbDpkZyBkdWxsIGFncmVlIG5vb2sgaHVuaw==
Content-Length: 514
Host: iisportaldev01
Content-Type: multipart/form-data;
boundary=---------------------------12199339629315
Content-Length: 402
[snip]
http.rb is unfortunately assuming I need Content-Type and Content-Length
headers added, even though I’m taking care of them myself in my data.
I’m not seeing a way to tell http.rb to stop with the “Content-” headers
as it appears to be messing things up.