java – org.springframework.web.client.HttpClientErrorException:400 Bad Request

前端之家收集整理的这篇文章主要介绍了java – org.springframework.web.client.HttpClientErrorException:400 Bad Request前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用弹簧靴.我有一个休息的api POST调用,我需要使用x-www-form-urlencoded发送正文,调用不需要头文件.我可以从邮递员中获取此URL,并在db中成功创建一行.但是当我尝试从Java调用它时,我收到400个错误的请求异常.

post request image

以下是我在Java中尝试过的内容.

MultiValueMap

我得到了这个例外.

org.springframework.web.client.HttpClientErrorException: 400 Bad Request

我也尝试过如下,并得到了同样的例外.

ResponseEntity

这是完整的堆栈跟踪

org.springframework.web.client.HttpClientErrorException: 400 Bad Request
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:641) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:357) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at com.bbtransact.icp.api.paymentmethodscards.internal.UserPaymentmethodsCardsServiceAgent.savePaymentCreditCards(UserPaymentmethodsCardsServiceAgent.java:59) ~[bin/:na]
    at com.bbtransact.icp.api.paymentmethodscards.resource.dao.CreditDebitCardsDAO.saveCreditDebitCard(CreditDebitCardsDAO.java:147) [bin/:na]
    at com.bbtransact.icp.api.paymentmethodscards.resource.dao.CreditDebitCardsDAO$$FastClassBySpringCGLIB$$12a57300.invoke(502) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_60]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_60]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.30.jar:8.0.30]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_60]

我该如何解决

最佳答案
这对我有用.问题是我使用交换方法时没有设置内容类型(标题).

MultiValueMap

ExternalCallBadRequestException和ExternalCallServerErrorException是这里的自定义异常.

注意:记住收到4xx错误时会抛出HttpClientErrorException.因此,如果您发送的请求设置标头或发送错误数据错误,您可能会收到此异常.

原文链接:https://www.f2er.com/spring/431832.html

猜你在找的Spring相关文章