在我的Ruby on Rails应用程序中,我试图通过Base64格式的POSTMAN REST客户端上传一张图像。当我张贴图像时,我得到了406不可接受的响应。当我检查我的数据库,图像在那里,并成功保存。

这个错误的原因是什么,我需要在我的头文件中指定什么吗?

我的要求:

URL——http://localhost:3000/exercises.json

标题:

Content-Type  -  application/json

原始数据:

{
    "exercise": {
        "subbodypart_ids": [
            "1",
            "2"
        ],
        "name": "Exercise14"
    },
    "image_file_name": "Pressurebar Above.jpg",
    "image":"******base64 Format*******"
}

当前回答

你的行动没有失败。

后端服务表示它返回的响应类型没有在客户端请求中的Accept HTTP报头中提供。

裁判:http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

找出服务返回的响应(内容类型)。 在请求Accept标头中提供此(内容类型)。

http://en.wikipedia.org/wiki/HTTP_status_code -> 406

其他回答

406不可接受 由请求标识的资源只能生成具有内容特征的响应实体 根据请求中发送的接受标头可接受。

406发生在服务器无法响应请求中指定的accept-header时。 在您的情况下,响应的application/json似乎不能被服务器接受。

就我而言,我补充说:

Content-Type: application/x-www-form-urlencoded

完全解决了我的问题。

你的行动没有失败。

后端服务表示它返回的响应类型没有在客户端请求中的Accept HTTP报头中提供。

裁判:http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

找出服务返回的响应(内容类型)。 在请求Accept标头中提供此(内容类型)。

http://en.wikipedia.org/wiki/HTTP_status_code -> 406

const request = require('request');

const headers = {
    'Accept': '*/*',
    'User-Agent': 'request',
};

const options = {
    url: "https://example.com/users/6",
    headers:  headers
};

request.get(options, (error, response, body) => {
    console.log(response.body);
});

在我的情况下,在.NET-Core中的API, API被设置为使用XML(默认设置为响应JSON),所以我在我的控制器中添加了这个注释:

[Produces("application/xml")]
public class MyController : ControllerBase {...}

谢谢你让我走上正路!