{"id":3793,"date":"2019-01-25T15:44:36","date_gmt":"2019-01-25T07:44:36","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3793"},"modified":"2019-01-25T15:44:36","modified_gmt":"2019-01-25T07:44:36","slug":"resttemplate-postforentity-400-bad-request-%e9%97%ae%e9%a2%98%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3793","title":{"rendered":"RestTemplate postForEntity 400 bad request \u95ee\u9898\u89e3\u51b3\u65b9\u6cd5"},"content":{"rendered":"<p>\n\t\u6700\u8fd1\u5728\u4f7f\u7528&nbsp;RestTemplate \u7684&nbsp;postForEntity \u65b9\u6cd5\u53d1\u8d77\u4e00\u4e2a\u8bf7\u6c42\uff0c\u603b\u662f\u63d0\u793a\uff1a400 bad request\uff0c\u7f51\u4e0a\u641c\u7d22\u4e86\u5f88\u4e45\uff0c\u6ca1\u6709\u76f8\u5173\u7684\u7b54\u6848\u3002\u4eca\u5929\u6211\u6765\u8bf4\u4e00\u4e0b\u8fd9\u4e2a\u95ee\u9898\u4ea7\u751f\u7684\u539f\u56e0\u3002\n<\/p>\n<p>\n\t\u9996\u5148\u770b\u5230\u8fd9\u4e2a\u95ee\u9898\uff0c\u4e0d\u8981\u4ea7\u751f\u6000\u7591\uff0c4xx \u5f00\u5934\u7684\u9519\u8bef\u90fd\u662f\u5ba2\u6237\u7aef\u9519\u8bef\u5f15\u8d77\u7684\u3002\u4e0d\u8981\u6000\u7591\u7b2c\u4e09\u65b9\u7684\u63a5\u53e3\u662f\u4e0d\u662f\u6709\u95ee\u9898\u3002\u6000\u7591\u5c31\u8bf4\u660e\u4f60\u4e0d\u61c2 http\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"RestTemplate \u5e95\u5c42\u4ee3\u7801\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fziuy9jozvj20od0de3zz.jpg\" style=\"width: 877px;height: 482px\" \/>\n<\/p>\n<h2>\n\t\u5e38\u89c1\u7684 HTTP \u72b6\u6001\u7801<br \/>\n<\/h2>\n<p>\n\t\u5e38\u89c1\u7684 HTTP \u72b6\u6001\u7801\u6709 5 \u7c7b\u3002\n<\/p>\n<ul>\n<li>\n\t\t\u6210\u529f Successful 2xx\uff1a\u6b64\u7c7b\u72b6\u6001\u7801\u6807\u8bc6\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u88ab\u6210\u529f\u63a5\u6536\u3001\u7406\u89e3\u5e76\u63a5\u53d7\u3002\u5e38\u89c1\u5982200\uff08OK\uff09\u3001204\uff08NoContent\uff09\u3002\n\t<\/li>\n<li>\n\t\t\u91cd\u5b9a\u5411 Redirection 3xx\uff1a\u8fd9\u4e2a\u7c7b\u522b\u7684\u72b6\u6001\u7801\u6807\u8bc6\u7528\u6237\u4ee3\u7406\u8981\u505a\u51fa\u8fdb\u4e00\u6b65\u7684\u52a8\u4f5c\u6765\u5b8c\u6210\u8bf7\u6c42\u3002\u5e38\u89c1\u5982301\uff08MovedPermanently\uff09\u3001302\uff08MovedTemprarily\uff09\u3002\n\t<\/li>\n<li>\n\t\t\u5ba2\u6237\u7aef\u9519\u8bef Client Error 4xx\uff1a4xx\u7c7b\u522b\u7684\u72b6\u6001\u7801\u662f\u5f53\u5ba2\u6237\u7aef\u8c61\u662f\u51fa\u9519\u7684\u65f6\u4f7f\u7528\u7684\u3002\u5e38\u89c1\u5982400\uff08BadRequest\uff09\u3001401\uff08Unauthorized\uff09\u3001403\uff08Forbidden\uff09\u3001404\uff08NotFound)\u3002\n\t<\/li>\n<li>\n\t\t\u670d\u52a1\u5668\u9519\u8bef Server Error 5xx\uff1a\u54cd\u5e94\u72b6\u6001\u7801\u4ee55\u5f00\u5934\u8868\u793a\u670d\u52a1\u5668\u77e5\u9053\u81ea\u5df1\u51fa\u9519\u6216\u8005\u6ca1\u6709\u80fd\u529b\u6267\u884c\u8bf7\u6c42\u3002\u5e38\u89c1\u5982500\uff08InternalServer Error\uff09\u3001502\uff08BadGateway\uff09\u3001504\uff08GatewayTimeout\uff09\u3002\n\t<\/li>\n<\/ul>\n<p>\n\t\u8bb0\u4f4f\u4e0a\u9762 4 \u6761\u5c31\u53ef\u4ee5\u4e86\u3002\u80fd\u79d2\u6740\u5927\u90e8\u5206\u5f02\u5e38\u60c5\u51b5\u3002\n<\/p>\n<h2>\n\tHTTP \u8bf7\u6c42\u7684\u65b9\u6cd5<br \/>\n<\/h2>\n<ul>\n<li>\n\t\tGET\uff1a\u901a\u8fc7\u8bf7\u6c42URI\u5f97\u5230\u8d44\u6e90\n\t<\/li>\n<li>\n\t\tPOST\uff1a\u7528\u4e8e\u6dfb\u52a0\u65b0\u7684\u5185\u5bb9\n\t<\/li>\n<li>\n\t\tPUT\uff1a\u7528\u4e8e\u4fee\u6539\u67d0\u4e2a\u5185\u5bb9\uff0c\u82e5\u4e0d\u5b58\u5728\u5219\u6dfb\u52a0\n\t<\/li>\n<li>\n\t\tDELETE\uff1a\u5220\u9664\u67d0\u4e2a\u5185\u5bb9\n\t<\/li>\n<li>\n\t\tOPTIONS \uff1a\u8be2\u95ee\u53ef\u4ee5\u6267\u884c\u54ea\u4e9b\u65b9\u6cd5\n\t<\/li>\n<li>\n\t\tHEAD \uff1a\u7c7b\u4f3c\u4e8eGET, \u4f46\u662f\u4e0d\u8fd4\u56debody\u4fe1\u606f\uff0c\u7528\u4e8e\u68c0\u67e5\u5bf9\u8c61\u662f\u5426\u5b58\u5728\uff0c\u4ee5\u53ca\u5f97\u5230\u5bf9\u8c61\u7684\u5143\u6570\u636e\n\t<\/li>\n<li>\n\t\tCONNECT \uff1a\u7528\u4e8e\u4ee3\u7406\u8fdb\u884c\u4f20\u8f93\uff0c\u5982\u4f7f\u7528SSL\n\t<\/li>\n<li>\n\t\tTRACE\uff1a\u7528\u4e8e\u8fdc\u7a0b\u8bca\u65ad\u670d\u52a1\u5668\n\t<\/li>\n<\/ul>\n<p>\n\tRestTempalte \u4e2d\u5bf9\u5e94 http \u8bf7\u6c42\u65b9\u6cd5\u7684\u64cd\u4f5c\u5982\u4e0b\uff1a\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"400 bad request\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fziv9vbgphj20eq0b5dgg.jpg\" style=\"width: 530px;height: 401px\" \/>\n<\/p>\n<p>\n\t\u73b0\u5728\u6211\u4eec\u6765\u8bf4\u4e0b\u5f00\u5934\u7684\u95ee\u9898\uff0c400 bad request\uff0c\u7ffb\u8bd1\u8fc7\u6765\u5c31\u662f\u8fd9\u4e2a\u8bf7\u6c42\u4e0d\u53cb\u597d\uff0c\u662f\u4e2a\u73af\u7684\u8bf7\u6c42\u3002\u90a3\u4e48\u600e\u4e48\u9020\u6210\u7684\u5462\uff1f\u80af\u5b9a\u662f\u4f60\u7684\u53c2\u6570\u4f20\u9012\u7684\u6709\u95ee\u9898\u3002\n<\/p>\n<p>\n\t\u6ce8\u610f\u914d\u5408\u8bf7\u6c42\u5934\u4e2d\u7684 Header\uff0c\u8bbe\u7f6e\u6b63\u786e\u7684 CONTENT_TYPE\uff0c\u6bd4\u5982\u662f application\/json \u6216 application\/xml \u7b49\u3002\n<\/p>\n<p>\n\t\u4e0d\u884c\u7684\u8bdd\uff0c\u4f60\u5c31\u5148\u7528 postman \u7b49\u5de5\u5177\u8c03\u7528\u4e00\u4e0b\uff0c\u8fd9\u4e2a\u9519\u8bef\u7edd\u5bf9\u662f\u4f60\u7684\u8bf7\u6c42\u5934\u9519\u8bef\uff0c\u8bf7\u6c42\u53c2\u6570\u8bbe\u7f6e\u9519\u8bef\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3793\">RestTemplate postForEntity 400 bad request \u95ee\u9898\u89e3\u51b3\u65b9\u6cd5<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5728\u4f7f\u7528&nbsp;RestTemplate \u7684&nbsp;postForEntity \u65b9\u6cd5\u53d1\u8d77\u4e00\u4e2a\u8bf7\u6c42\uff0c\u603b [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[124,1749,1481,1153,1906],"class_list":["post-3793","post","type-post","status-publish","format-standard","hentry","category-yyzt","tag-http","tag-http-3","tag-resttemplate"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3793"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3793\/revisions"}],"predecessor-version":[{"id":3794,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3793\/revisions\/3794"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}