小编Chr*_*nev的帖子

POST 到 web api 时不支持的媒体类型

这是客户端

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);

    }
}   
Run Code Online (Sandbox Code Playgroud)

服务器

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

}  
Run Code Online (Sandbox Code Playgroud)

我收到错误:

415 不支持的媒体类型

一直 - 此资源不支持请求实体的媒体类型“应用程序/八位字节流”。我该怎么办?我在这里找到了一些已回答的主题,但没有帮助。

asp.net rest asp.net-web-api

5
推荐指数
1
解决办法
2567
查看次数

标签 统计

asp.net ×1

asp.net-web-api ×1

rest ×1