Note that there are some explanatory texts on larger screens.

plurals
  1. POSending files like a form with ocaml-curl
    text
    copied!<p>I'm working on a little tool to upload my school work on the dedicated server my school provides, and I've decided to use <code>ocaml</code> and <code>ocurl</code>, an <code>ocaml</code> wrapper for <code>libcurl</code>. I'm able to retrieve do everything I want from the command line (using curl), but can't upload the file with ocurl.</p> <p>I think this is because the server page expects <code>multipart/form-data</code> as then content type. After reading the <code>libcurl</code> documentation I used <code>curl_formadd()</code> (and that's what I do from command line), but ocurl is not able to do that (I did not find anything like this in <code>curl.ml</code>)</p> <p>Working curl command line:</p> <pre><code>curl -v "myhost/upload2.php" --form "fichier1= @file.tar.gz" --form "MAX_FILE_SIZE=1000000" -b cookie </code></pre> <p>Response</p> <pre><code>&gt; POST /upload2.php HTTP/1.1 &gt; User-Agent: curl/7.32.0 &gt; Host: myhost &gt; Accept: */* &gt; Cookie: PHPSESSID=4qbihrkhode23902q1v988a114; cookie_test=1 &gt; Content-Length: 10563 &gt; Expect: 100-continue &gt; Content-Type: multipart/form-data; boundary=------------------------53aa2e4a08d1f7c0 &gt; &lt; HTTP/1.1 100 Continue &lt; HTTP/1.1 200 OK &lt; Date: Wed, 23 Oct 2013 17:34:21 GMT * Server Apache/2.2.16 (Debian) is not blacklisted &lt; Server: Apache/2.2.16 (Debian) &lt; X-Powered-By: PHP/5.3.3-7+squeeze17 &lt; Expires: Thu, 19 Nov 1981 08:52:00 GMT &lt; Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 &lt; Pragma: no-cache &lt; Vary: Accept-Encoding &lt; Content-Length: 2265 &lt; Content-Type: text/html &lt; </code></pre> <p>My closest non-working <code>ocaml</code> code</p> <pre><code>let fetch connection url = Printf.printf "Retriving %s ...\n" (url); flush stdout; Curl.set_url connection url; Curl.perform connection; Curl.set_post connection false in Curl.global_init Curl.CURLINIT_GLOBALALL; let connection = Curl.init() in Curl.set_verbose connection true; let curl_file_option = Curl.CURLFORM_FILECONTENT("fichier1","file.tar.gz",Curl.CONTENTTYPE "application/x-tar") in Curl.set_maxfilesize connection (Int32.of_int 1000000); Curl.set_httppost connection [curl_file_option]; fetch connection (baseURL^"upload2.php"); ;; </code></pre> <p>Which does absolutely nothing but using 100% CPU</p> <p>Finally, the question is : could you help me building my own formdata function ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload