Mezeo Ready Developer Center
May 17, 2012, 06:42:21 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
Author Topic: Unsupported Media Type  (Read 515 times)
Mark Aldred
Newbie
*
Posts: 16


View Profile
« on: July 01, 2010, 11:16:51 AM »

Hi, I am having a bit of trouble with POST.  My application uses libcurl rather than curl so I am working at a lower level.  I can use the curl cli to POST a file successfully, but when I issue a POST with my application through libcurl I get back:

HTTP/1.1 415 Unsupported Media Type
 Date: Thu, 01 Jul 2010 14:28:44 GMT
 Server: Apache/2.2.3 (Red Hat)
 Transfer-Encoding: chunked
 Content-Type: text/plain; charset=UTF-8

I see that when the curl CLI issue a POST request it uses
    Content-Type: multipart/form-data; boundary=----------------------------327b88df9f62

Do I need to use this Content-Type?  I'm reading through RFC 2616 now looking clues there. 
Logged
Travis McLane
Mezeo Employee
Newbie
*****
Posts: 21



View Profile
« Reply #1 on: July 01, 2010, 11:23:31 AM »

Can you please post the URI to which you are posting the the request?

Only the ContainerContents resource accepts a multipart/form-data post at this time.
The reference guide will be corrected to reflect this oversight.
« Last Edit: July 01, 2010, 11:25:20 AM by Travis McLane » Logged
Mark Aldred
Newbie
*
Posts: 16


View Profile
« Reply #2 on: July 01, 2010, 12:10:33 PM »

 POST /v2/containers/7C6C2794-3E78-11DF-8EF9-97EBB2A360EE/contents HTTP/1.1

Logged
Mark Aldred
Newbie
*
Posts: 16


View Profile
« Reply #3 on: July 01, 2010, 01:25:44 PM »

This URI is valid for POST, right?  What are the valid content-type values that I can use for POST?  The Developer Guide and the API Reference Guide say to look in the Resource Specification.  Where can I find the Resource Specification?
Logged
Travis McLane
Mezeo Employee
Newbie
*****
Posts: 21



View Profile
« Reply #4 on: July 01, 2010, 05:26:16 PM »

The reference guide I referenced is found at the following link:
http://developer.mezeo.com/mezeo-developer-center/documentation/api-documentation/

The allowed types are found at the following url:
http://developer.mezeo.com/mezeo-developer-center/documentation/api-documentation/#resource_type_containercontents

What Content-Type are you submitting?
If you are posting a multipart/form-data entity then your Content-Type header needs to contain the boundary that you are using for the form data.

The URI you are using is valid so I am unsure why the response you provide would be sent.
At this point I recommend using wireshark and examining the difference in the 'curl' command line program request to what libcurl is submitting to the server.

I recommend you use a small text file for this test so that the data captured will not be binary.


Logged
Mark Aldred
Newbie
*
Posts: 16


View Profile
« Reply #5 on: July 02, 2010, 09:36:18 AM »

Hi Travis,

My data is not form data.  It is binary.  I would rather not use multipart/form-data. Am I required to use mulipart/form-data? 
Are any other Content-Types supported? 
Is "Entity-Type" in the API Reference Guide the same as "Content-Type" in RFC 2616?

I have issued a POST command using the curl CLI with success.  I ran it with the -v option to see the headers.  My application also causes libcurl to display the headers in use.  There and only two differences that I see.
1) My application does not set the User-Agent header.  I doubt that this matters.
2) the Content-Type

Below are first the successful post from the curl CLI and then several failed attempts from my application showing all headers.

POST /v2/containers/7C6C2794-3E78-11DF-8EF9-97EBB2A360EE/contents HTTP/1.1
> Authorization: Basic
> User-Agent: curl/7.19.5 (x86_64-pc-linux-gnu) libcurl/7.20.0 OpenSSL/0.9.8n zlib/1.2.3.3
> Host: pcsbeta.mezeo.net
> Accept: */*
> X-Client-Specification: 2
> Content-Length: 661
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------327b88df9f62
>
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 100 Continue
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 201 Created


From my application I have tried several Content-Types.  Here are the types and results:

CURLINFO_HEADER_OUT eh:0x2334de8 POST /v2/containers/7C6C2794-3E78-11DF-8EF9-97EBB2A360EE/contents HTTP/1.1
CURLINFO_HEADER_OUT eh:0x2334de8 Authorization: Basic
CURLINFO_HEADER_OUT eh:0x2334de8 Host: pcsbeta.mezeo.net
CURLINFO_HEADER_OUT eh:0x2334de8 X-Client-Specification: 2
CURLINFO_HEADER_OUT eh:0x2334de8 accept: */*
CURLINFO_HEADER_OUT eh:0x2334de8 content-length: 4096
CURLINFO_HEADER_OUT eh:0x2334de8 content-type: application/vnd.csp.file-info+xml
CURLINFO_HEADER_OUT eh:0x2334de8 Expect: 100-continue
CURLINFO_HEADER_IN eh:0x2334de8 HTTP/1.1 100 Continue
CURLINFO_HEADER_IN eh:0x2334de8 HTTP/1.1 500 Internal Server Error
CURLINFO_HEADER_IN eh:0x2334de8 Date: Fri, 02 Jul 2010 11:44:05 GMT
CURLINFO_HEADER_IN eh:0x2334de8 Server: Apache/2.2.3 (Red Hat)
CURLINFO_HEADER_IN eh:0x2334de8 Connection: close
CURLINFO_HEADER_IN eh:0x2334de8 Transfer-Encoding: chunked
CURLINFO_HEADER_IN eh:0x2334de8 Content-Type: text/plain; charset=UTF-8



CURLINFO_HEADER_OUT eh:0x1c66e08 POST /v2/containers/7C6C2794-3E78-11DF-8EF9-97EBB2A360EE/contents HTTP/1.1
CURLINFO_HEADER_OUT eh:0x1c66e08 Authorization: Basic
CURLINFO_HEADER_OUT eh:0x1c66e08 Host: pcsbeta.mezeo.net
CURLINFO_HEADER_OUT eh:0x1c66e08 X-Client-Specification: 2
CURLINFO_HEADER_OUT eh:0x1c66e08 accept: */*
CURLINFO_HEADER_OUT eh:0x1c66e08 content-length: 4096
CURLINFO_HEADER_OUT eh:0x1c66e08 content-type: application/vnd.csp.container-info+xml
CURLINFO_HEADER_OUT eh:0x1c66e08 Expect: 100-continue
CURLINFO_HEADER_IN eh:0x1c66e08 HTTP/1.1 100 Continue
CURLINFO_HEADER_IN eh:0x1c66e08 HTTP/1.1 500 Internal Server Error
CURLINFO_HEADER_IN eh:0x1c66e08 Date: Fri, 02 Jul 2010 13:12:55 GMT
CURLINFO_HEADER_IN eh:0x1c66e08 Server: Apache/2.2.3 (Red Hat)
CURLINFO_HEADER_IN eh:0x1c66e08 Connection: close
CURLINFO_HEADER_IN eh:0x1c66e08 Transfer-Encoding: chunked
CURLINFO_HEADER_IN eh:0x1c66e08 Content-Type: text/plain; charset=UTF-8





CURLINFO_HEADER_OUT eh:0x13a9e08 POST /v2/containers/7C6C2794-3E78-11DF-8EF9-97EBB2A360EE/contents HTTP/1.1
CURLINFO_HEADER_OUT eh:0x13a9e08 Authorization: Basic
CURLINFO_HEADER_OUT eh:0x13a9e08 Content-Type: application/octet-stream
CURLINFO_HEADER_OUT eh:0x13a9e08 Host: pcsbeta.mezeo.net
CURLINFO_HEADER_OUT eh:0x13a9e08 X-Client-Specification: 2
CURLINFO_HEADER_OUT eh:0x13a9e08 accept: */*
CURLINFO_HEADER_OUT eh:0x13a9e08 content-length: 4096
CURLINFO_HEADER_OUT eh:0x13a9e08 Expect: 100-continue
CURLINFO_HEADER_IN eh:0x13a9e08 HTTP/1.1 415 Unsupported Media Type
CURLINFO_HEADER_IN eh:0x13a9e08 Date: Fri, 02 Jul 2010 13:14:20 GMT
CURLINFO_HEADER_IN eh:0x13a9e08 Server: Apache/2.2.3 (Red Hat)
CURLINFO_HEADER_IN eh:0x13a9e08 Transfer-Encoding: chunked
CURLINFO_HEADER_IN eh:0x13a9e08 Content-Type: text/plain; charset=UTF-8



CURLINFO_HEADER_OUT eh:0x2ba5e08 POST /v2/containers/7C6C2794-3E78-11DF-8EF9-97EBB2A360EE/contents HTTP/1.1
CURLINFO_HEADER_OUT eh:0x2ba5e08 Authorization: Basic
CURLINFO_HEADER_OUT eh:0x2ba5e08 Host: pcsbeta.mezeo.net
CURLINFO_HEADER_OUT eh:0x2ba5e08 X-Client-Specification: 2
CURLINFO_HEADER_OUT eh:0x2ba5e08 accept: */*
CURLINFO_HEADER_OUT eh:0x2ba5e08 content-length: 4096
CURLINFO_HEADER_OUT eh:0x2ba5e08 content-type: binary
CURLINFO_HEADER_OUT eh:0x2ba5e08 Expect: 100-continue
CURLINFO_HEADER_IN eh:0x2ba5e08 HTTP/1.1 415 Unsupported Media Type
CURLINFO_HEADER_IN eh:0x2ba5e08 Date: Fri, 02 Jul 2010 13:15:27 GMT
CURLINFO_HEADER_IN eh:0x2ba5e08 Server: Apache/2.2.3 (Red Hat)
CURLINFO_HEADER_IN eh:0x2ba5e08 Transfer-Encoding: chunked
CURLINFO_HEADER_IN eh:0x2ba5e08 Content-Type: text/plain; charset=UTF-8


CURLINFO_HEADER_OUT eh:0x2c29d48 POST /v2/containers/7C6C2794-3E78-11DF-8EF9-97EBB2A360EE/contents HTTP/1.1
CURLINFO_HEADER_OUT eh:0x2c29d48 Authorization: Basic
CURLINFO_HEADER_OUT eh:0x2c29d48 Content-Type: text/plain
CURLINFO_HEADER_OUT eh:0x2c29d48 Host: pcsbeta.mezeo.net
CURLINFO_HEADER_OUT eh:0x2c29d48 X-Client-Specification: 2
CURLINFO_HEADER_OUT eh:0x2c29d48 accept: */*
CURLINFO_HEADER_OUT eh:0x2c29d48 content-length: 4096
CURLINFO_HEADER_OUT eh:0x2c29d48 Expect: 100-continue
CURLINFO_HEADER_IN eh:0x2c29d48 HTTP/1.1 415 Unsupported Media Type
CURLINFO_HEADER_IN eh:0x2c29d48 Date: Fri, 02 Jul 2010 13:16:13 GMT
CURLINFO_HEADER_IN eh:0x2c29d48 Server: Apache/2.2.3 (Red Hat)
CURLINFO_HEADER_IN eh:0x2c29d48 Transfer-Encoding: chunked
CURLINFO_HEADER_IN eh:0x2c29d48 Content-Type: text/plain; charset=UTF-8
Logged
Travis McLane
Mezeo Employee
Newbie
*****
Posts: 21



View Profile
« Reply #6 on: July 02, 2010, 10:53:22 AM »

Creating a file with contents using a single POST requires that it be submitted using a multi-part/form post data.

If you first create the file by submitting the application/vnd.csp.file-info+xml entity data to the ContainerContents resource you may then do a PUT of the binary data of the file without using a multi-part/form to the URI returned which will be the newly created resource's uri.

You can duplicate this using the command line curl by doing the following sequence:
 - curl -u <username>:<password> https://cloud.example.com/v2/containers/<oid>/contents -X POST -H "Content-Type: application/vnd.csp.file-info+xml" -d "<file><name>New File.txt</name><mime_type>application/txt</mime_type><public>false</public></file>"

This will return a new resource uri of the form:

https://cloud.example.com/v2/files/<oid>

Replace the content of the file by putting your file data to the 'content' uri of the file resource returned.

curl -u <username>:<password> https://cloud.example.com/v2/files/<oid>/content -X PUT -d @testfile.txt -v

You should receive a "204 No Content" as the response.

Which language are you using to drive libcurl?
A self contained example would be helpful in solving this issue.
Logged
Mark Aldred
Newbie
*
Posts: 16


View Profile
« Reply #7 on: July 02, 2010, 11:07:31 AM »

I am using C++.  I will investigate a zero length POST followed by a PUT.  I appreciate you support. 
Logged
Pages: [1]
 
Jump to:  

© Mezeo Software. All rights reserved. | Privacy Policies | Contact Us | Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC