在我的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*******"
}

当前回答

当浏览器中存储或引用无效的cookie时,您也可以收到406响应—例如,在本地以Dev模式运行Rails服务器时。

如果碰巧在同一个端口上运行两个不同的项目,浏览器可能会引用来自不同localhost会话的cookie。

这种事就发生在我身上……让我一时糊涂。在浏览器> Developer Mode > Network中显示。

其他回答

如果你正在使用'request.js',你可能会使用以下代码:

var options = {
  url: 'localhost',
  method: 'GET',
  headers:{
    Accept: '*/*'
  }
}

request(options, function (error, response, body) {
  ...
})

将报头更改为接受:*/*解决了我的问题,并确保您没有任何其他接受报头

就我而言,我补充说:

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

完全解决了我的问题。

当浏览器中存储或引用无效的cookie时,您也可以收到406响应—例如,在本地以Dev模式运行Rails服务器时。

如果碰巧在同一个端口上运行两个不同的项目,浏览器可能会引用来自不同localhost会话的cookie。

这种事就发生在我身上……让我一时糊涂。在浏览器> Developer Mode > Network中显示。

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