0

I want to use Ruby Mechanize to write an auto file uploading script for a website. But the read upload step of the website is done by a Flash file. I use fiddler captured the traffic from the Flash file to the server. Here is it.

POST /upload.php HTTP/1.1
Accept: text/*
Content-Type: multipart/form-data; boundary=----------KM7KM7Ij5KM7KM7ei4GI3GI3gL6GI3
User-Agent: Shockwave Flash
Host: 119.147.15.17<this is fake IP address>
Content-Length: 7800236
Connection: Keep-Alive
Pragma: no-cache

------------KM7KM7Ij5KM7KM7ei4GI3GI3gL6GI3
Content-Disposition: form-data; name="Filename"

learning_objectives.flv
------------KM7KM7Ij5KM7KM7ei4GI3GI3gL6GI3
Content-Disposition: form-data; name="FileData"; filename="learning_objectives.flv"
Content-Type: application/octet-stream

This_is_the_real_data_in_learning_objectives.flv

My question is how can I simulate this post requrest? Currently what I can think of is create a form by myself and add an input element with type file. Then submit this form with customized headers (such as the user-agent etc.). But I'm still have difficult in dealing with the file upload part. Anyone can help me with it? Thanks!

Just a learner
  • 26,690
  • 50
  • 155
  • 234
  • Have you looked at the mechanize code to figure out how it handles multipart forms? You should be able to adapt the code used there to send a custom multipart request. – Niklas B. Mar 03 '12 at 16:12

1 Answers1

1

It should look something like this:

agent.post url, 'FileData' => File.new('learning_objectives.flv')
pguardiario
  • 53,827
  • 19
  • 119
  • 159