Unsupported Media Types when POST to web api

Viewed 3248

Here is the client :

using (var client = new HttpClient())
{

    client.BaseAddress = new Uri("http://localhost/MP.Business.Implementation.FaceAPI/");
    client.DefaultRequestHeaders
            .Accept
            .Add(new MediaTypeWithQualityHeaderValue("application/octet-stream"));
    using (var request = new HttpRequestMessage(HttpMethod.Post, client.BaseAddress + "api/Recognition/Recognize"))
    {
        request.Content = new ByteArrayContent(pic);
        request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

        await client.PostAsync(request.RequestUri, request.Content);

    }
}   

and the server :

[System.Web.Http.HttpPost]
public string Recognize(byte[] img)
{
    //do someth with the byte []

}  

I am getting error:

415 Unsupported Media Type

all the time - The request entity's media type 'application/octet-stream' is not supported for this resource. What can i do about it? I've found some answered threads here , but it didnt help.

1 Answers
Related