I'm trying to make a RESTful server in Erlang with Cowboy, and I'm having trouble due to the fact that I know nothing about HTTP requests. I can't find an example of a RESTful file upload request, only a normal one.
This works for a regular HTTP server (found in the Cowboy examples) to upload the file compile.sh
, which contains git add * ; git commit -a -m "upload" ; git push
:
POST /upload HTTP/1.1
Host: 169.229.85.167:8080
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryd1YD0OADcYFcuL0v
Origin: http://169.229.85.167:8080
Accept-Encoding: gzip, deflate
Authorization: Basic cmltcm9jazpwYXNzd29yZA==
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/7.1 Safari/537.85.10
Referer: http://169.229.85.167:8080/
Content-Length: 243
Accept-Language: en-us
------WebKitFormBoundaryd1YD0OADcYFcuL0v
Content-Disposition: form-data; name="inputfile"; filename="upload.sh"
Content-Type: application/x-sh
git add * ; git commit -a -m "upload" ; git push
------WebKitFormBoundaryd1YD0OADcYFcuL0v--
But if I send this request to a RESTful server, I get this response:
HTTP/1.1 415 Unsupported Media Type
connection: keep-alive
server: Cowboy
date: Fri, 24 Oct 2014 04:34:06 GMT
content-length: 0
content-type: text/html
vary: accept
Now, I may have done the RESTful server wrong, but I'm not sure. A lot of it is encapsulated in Cowboy, so I don't really know how it works. Is the request supposed to be different for a RESTful server?