Issue
There is a content system for which i want to automize the file upload. When I upload a file manually the browser executes exactly 1 POST request:
curl 'http://servers-ip-address/webtest/vmweb'
-H 'Origin: http://servers-ip-address'
-H 'Accept-Encoding: gzip, deflate'
-H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7'
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
-H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryYdSASYyCSQjGlu54'
-H 'Accept: */*' -H 'Referer: http://servers-ip-address/webtest/vmsf/1531725119/client/A78837FE722B13434138152B7DCC947C.cache.html'
-H 'Cookie: LASTUSERNAME=myusername; LASTUSERDOMAIN=""; JSESSIONID=mysessionid; XSRF-TOKEN=myxsrftoken; GLog=%7B%0D%20%20%20%20trackRPC%3Afalse%0D%7D'
-H 'Connection: keep-alive'
--data-binary $'------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="upload_file"; filename="abcd.png"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="task"\r\n\r\nbov\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="xst"\r\n\r\ntmvattachaddfiledrop\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="windowid"\r\n\r\n56\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="xcpwinid"\r\n\r\n57\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="actionmoniker"\r\n\r\nde..metamodel.LinkRelationAction-1337#\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="xsrftoken"\r\n\r\nmyxsrftoken\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54--\r\n'
--compressed
When I execute this curl statement, the server accepts the request and displays the file on the system. Unfortunately the file is empty.
tried solution: I assume i have to use the @ character to reference the file. But as per documentation everything after @ has to be the filename. Now if i split the --data-binary into multiple statements
--data-binary $'------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="upload_file"; '
--data-binary '[email protected]'
--data-binary '\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="task"\r\n\r\nbov\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="xst"\r\n\r\ntmvattachaddfiledrop\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="windowid"\r\n\r\n56\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="xcpwinid"\r\n\r\n57\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="actionmoniker"\r\n\r\nde..metamodel.LinkRelationAction-1337#\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54\r\nContent-Disposition: form-data; name="xsrftoken"\r\n\r\nmyxsrftoken\r\n------WebKitFormBoundaryYdSASYyCSQjGlu54--\r\n'
it wont work as curl joins the statements with the & character
How can I put the file (or correct reference) into the --data-binary ?
Solution
there's pretty much never any reason to craft the multipart/form-data request manually. just use the -F parameter, in your case
-F [email protected] -F task=bov -F xst=tmvattachaddfiledrop -F windowid=56 -F xcpwinid=57 -F actionmoniker='de..metamodel.LinkRelationAction-1337#' -F xsrftoken=myxsrftoken
, and curl will create the multipart/form-data stuff for you.
also remove the Content-Type: multipart/form-data;
header, curl will add it, and set the appropriate boundary, wheras you will set the wrong boundary (and if you set the header manually, curl won't override your custom header, but if you don't set it, curl will create it for you.)
Answered By - hanshenrik Answer Checked By - Mildred Charles (WPSolving Admin)