Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Encoding a multipart/form-data for posting via HTTP
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dave Burt  
View profile  
 More options Mar 10 2005, 3:47 am
Newsgroups: comp.lang.ruby
From: "Dave Burt" <d...@burt.id.au>
Date: Thu, 10 Mar 2005 08:47:15 GMT
Local: Thurs, Mar 10 2005 3:47 am
Subject: Re: Encoding a multipart/form-data for posting via HTTP
It sounds to me as if this should be in Net::HTTP::Post.

"Dema" <demetriusnu...@gmail.com> offered:

> After googling around (with no luck) for a while for a function that
> would encode a hash into a multipart/form-data to be sent to a HTTP
> server via POST, I decided to read the RFC and write my own. In fact,
> it's not that complicated and I would like to share it just in case
> someone else needs it:

> BOUNDARY = "AaB03x"
> def encode_multipartformdata(parameters = {})
>  ret = String.new
>  parameters.each do |key, value|
>    unless value.empty?
>      ret << "\r\n--" << BOUNDARY << "\r\n"
>      ret << "Content-Disposition: form-data; name=\"#{key}\"\r\n\r\n"
>      ret << value
>    end
>  end
>  ret << "\r\n--" << BOUNDARY << "--\r\n"
> end

> I got stuck for a while on the boundary syntax and the \r\n stuff, but
> eventually it worked ok.

> I just needed it to send some data to a RDF database that offers a HTTP
> API channel. So, this only works for the simplest case. There are some
> more complex variations, like uploading one or more files, setting
> individual content types for each part, etc.

> rgds
> Dema


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.