Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > posting multipart form through http.rb

Reply
Thread Tools

posting multipart form through http.rb

 
 
Chris Morris
Guest
Posts: n/a
 
      09-10-2003
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:ost.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.

--

Chris
http://clabs.org/blogki



 
Reply With Quote
 
 
 
 
ts
Guest
Posts: n/a
 
      09-10-2003
>>>>> "C" == Chris Morris <(E-Mail Removed)> writes:

C> # data equals the above stuff
C> # @h is my http object
C> req = Net::HTTP:ost.new(get_url)

Net::HTTP:ost::new give you the possibility to add headers lines, try
with

headers = {}
headers['Content-Type'] = ''multipart/form-data; etc... '
req = Net::HTTP:ost.new(get_url, headers)

and remove these headers lines (Content-*) in the data that you send


Guy Decoux


 
Reply With Quote
 
 
 
 
Chris Morris
Guest
Posts: n/a
 
      09-10-2003
ts wrote:

>C> # data equals the above stuff
>C> # @h is my http object
>C> req = Net::HTTP:ost.new(get_url)
>
> Net::HTTP:ost::new give you the possibility to add headers lines, try
> with
>
> headers = {}
> headers['Content-Type'] = ''multipart/form-data; etc... '
> req = Net::HTTP:ost.new(get_url, headers)
>
> and remove these headers lines (Content-*) in the data that you send
>
>

Yeah, I just realized this ... I'd misassumed the Content-Type and
-Length headers weren't just normal headers that could go anywhere in
the http headers portion, based on one packet sniff I got from a
browser. Sniffed another browser and saw a different arrangement, so,
it's not working for me yet, but my original post was bunk.

--

Chris
http://clabs.org/blogki



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Encoding a multipart/form-data for posting via HTTP Dema Ruby 3 08-22-2012 09:26 PM
HTML File Upload using enctype=multipart/form-data in form? Matt Java 8 05-26-2012 07:40 AM
How to retrieve form field value if form is EncType=multipart/form-dataForm? Li Zhang ASP .Net 4 02-27-2009 01:23 AM
MIME Structure Multipart/Mixed with attachment and Multipart/Alternative blaine@worldweb.com Perl Misc 1 04-04-2007 08:23 PM
Action called twice when form enctype is multipart/form-data Duncan Java 0 02-24-2006 11:18 AM



Advertisments