我有一个发布请求,我需要发送 x-www-form-urlencoded keyValue 对参数,内容类型应该是 x-www-form-urlencoded。
\n\n在编码之前,我已经在邮递员中成功尝试过,只需添加 Header"Content-Type=application/x-www-form-urlencoded" 和 x-www-form-urlencoded body 。
\n\n这是我的代码:`
\n\n RestAssured.baseURI="****"\n RequestSpecification request = RestAssured.given().config(RestAssured.config()\n .encoderConfig(EncoderConfig.encoderConfig()\n .encodeContentTypeAs("x-www-form-urlencoded",\n ContentType.URLENC)))\n .contentType(ContentType.URLENC.withCharset("UTF-8"))\n .formParam("grant_type", *)\n .formParam("code", *)\n .formParam("client_id",*)\n .when().log().all()\n .then().log().all().request()\n request.post("/oauth2/token")`\nRun Code Online (Sandbox Code Playgroud)\n\n我想放心发布为 formParam 而不是“x-www-form-urlencoded”?\n这是放心日志:`
\n\nRequest method: POST\nRequest URI: ***\nProxy: <none>\nRequest params: <none>\nQuery params: <none>\nForm params: grant_type=***\n code=***\n client_id=***\nPath params: <none>\nHeaders: Accept=image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap\n Content-Type=application/x-www-form-urlencoded; charset=UTF-8\nCookies: <none>\nMultiparts: <none>\nBody: <none>\nHTTP/1.1 405 Method Not Allowed\nContent-Length: 61\nDate: Tue, 30 Jan 2018 06:59:20 GMT\nX-Correlationid: 5d155b6f-0d85-4775-5f50-82c397e5b44b\nX-Smp-Log-Correlation-Id: 5d155b6f-0d85-4775-5f50-82c397e5b44b\nX-Vcap-Request-Id: 5d155b6f-0d85-4775-5f50-82c397e5b44b\nOnly support Content-Type\xef\xbc\x9aapplication/x-www-form-urlencoded\n …Run Code Online (Sandbox Code Playgroud)