Cyb*_*ber 179 rest json http http-response-codes http-status-code-406
在我的Ruby on Rails应用程序中,我尝试以Base64格式通过POSTMAN REST客户端上传图像.当我发布图像时,我得到了406 Not Acceptable Response.当我检查我的数据库时,图像就在那里并成功保存.
这个错误的原因是什么,我需要在标题中指定什么?
我的请求:
网址--- http://localhost:3000/exercises.json
标题:
Content-Type - application/json
Run Code Online (Sandbox Code Playgroud)
原始数据:
{
"exercise": {
"subbodypart_ids": [
"1",
"2"
],
"name": "Exercise14"
},
"image_file_name": "Pressurebar Above.jpg",
"image":"******base64 Format*******"
}
Run Code Online (Sandbox Code Playgroud)
The*_*bit 255
你的手术没有失败.
您的后端服务表示客户端请求中的Accept HTTP标头中未提供它返回的响应类型.
参考:http://en.wikipedia.org/wiki/List_of_HTTP_header_fields
http://en.wikipedia.org/wiki/HTTP_status_code - > 406
ash*_*ina 39
406不可接受请求标识的资源仅能够根据请求中发送的接受标头生成具有不可接受的内容特征的响应实体.
当服务器无法使用请求中指定的accept-header进行响应时,会发生406.在您的情况下,响应的application/json似乎可能不被服务器接受.
小智 7
你提到你使用Ruby on Rails作为后端.您没有发布相关方法的代码,但我的猜测是它看起来像这样:
def create
post = Post.create params[:post]
respond_to do |format|
format.json { render :json => post }
end
end
Run Code Online (Sandbox Code Playgroud)
将其更改为:
def create
post = Post.create params[:post])
render :json => post
end
Run Code Online (Sandbox Code Playgroud)
它会解决你的问题.它对我有用:)
“有时”这可能意味着服务器出现内部错误,并且想要响应错误消息(例如:带有 JSON 负载的 500),但由于请求标头没有说明它接受 JSON,因此它返回 406。去搞清楚。(在本例中:spring boot webapp)。
在这种情况下,您的操作确实失败了。但失败消息被另一条消息掩盖了。
归档时间: |
|
查看次数: |
415217 次 |
最近记录: |