{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}

本文介绍了一种在使用curl命令向Elasticsearch上传文档时遇到的问题及解决方案。当尝试用curl-XPOST命令发送JSON格式的数据到Elasticsearch时,由于Content-Type设置不正确导致返回错误406。文章提供了正确的curl命令示例,包括如何设置Content-Type为application/json。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述

curl -XPOST  'localhost:9200/books/es/1' -d '{"title":"Elasticsearch Server", "pubilished":2013}'

{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}


需要指定对应的header头: -H "Content-Type: application/json"

解决方法

curl -H "Content-Type: application/json" -XPOST 'localhost:9200/books/es/1' -d '{"title":"Elasticsearch Server", "publicshed":2013}'


摘自:https://blog.youkuaiyun.com/dtiove/article/details/78870607

2025-06-10 15:28:30.181 INFO 90192 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2025-06-10 15:28:30.181 INFO 90192 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2025-06-10 15:28:30.182 DEBUG 90192 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Detected StandardServletMultipartResolver 2025-06-10 15:28:30.182 DEBUG 90192 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Detected AcceptHeaderLocaleResolver 2025-06-10 15:28:30.182 DEBUG 90192 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Detected FixedThemeResolver 2025-06-10 15:28:30.184 DEBUG 90192 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@59933644 2025-06-10 15:28:30.184 DEBUG 90192 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Detected org.springframework.web.servlet.support.SessionFlashMapManager@12f9f896 2025-06-10 15:28:30.184 DEBUG 90192 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data 2025-06-10 15:28:30.184 INFO 90192 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 3 ms 2025-06-10 15:28:30.194 DEBUG 90192 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : OPTIONS "/api/auth/login", parameters={} 2025-06-10 15:28:30.202 DEBUG 90192 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.hnkj.webdemo.controller.AuthController#login(String, String, String) 2025-06-10 15:28:30.217 DEBUG 90192 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed 200 OK 2025-06-10 15:28:30.224 DEBUG 90192 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : POST "/api/auth/login", parameters={} 2025-06-10 15:28:30.224 DEBUG 90192 --- [nio-8080-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.hnkj.webdemo.controller.AuthController#login(String, String, String) 2025-06-10 15:28:30.238 DEBUG 90192 --- [nio-8080-exec-5] o.s.web.method.HandlerMethod : Could not resolve parameter [0] in public java.util.Map<java.lang.String, java.lang.Object> com.hnkj.webdemo.controller.AuthController.login(java.lang.String,java.lang.String,java.lang.String): Required request parameter 'userName' for method parameter type String is not present 2025-06-10 15:28:30.240 WARN 90192 --- [nio-8080-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'userName' for method parameter type String is not present] 2025-06-10 15:28:30.240 DEBUG 90192 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : Completed 400 BAD_REQUEST 2025-06-10 15:28:30.243 DEBUG 90192 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for POST "/error", parameters={} 2025-06-10 15:28:30.246 DEBUG 90192 --- [nio-8080-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest) 2025-06-10 15:28:30.259 DEBUG 90192 --- [nio-8080-exec-5] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Using 'application/json', given [*/*] and supported [application/json, application/*+json, application/json, application/*+json] 2025-06-10 15:28:30.260 DEBUG 90192 --- [nio-8080-exec-5] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [{timestamp=Tue Jun 10 15:28:30 CST 2025, status=400, error=Bad Request, path=/api/auth/login}] 2025-06-10 15:28:30.294 DEBUG 90192 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 400 后端终端返回信息 login.html:334 POST http://localhost:8080/api/auth/login 400 (Bad Request) (anonymous) @ login.html:334 setTimeout (anonymous) @ login.html:332 开发者日志报告 通过以上两端信息能够发现什么问题
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值