如何发布睡觉保证的x-www-urlencode请求 [英] How to post x-www-urlencode request by rest assured
本文介绍了如何发布睡觉保证的x-www-urlencode请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个POST请求,其中需要发送x-www-form-urlencoded keyValue对参数,并且内容类型应为x-www-form-urlencode。
在编码之前,我已经在邮递员中成功尝试过,只是添加了带有x-www-Header"Content-Type=application/x-www-form-urlencoded"-urlencode正文的表单。
以下是我的代码:`
RestAssured.baseURI="****"
RequestSpecification request = RestAssured.given().config(RestAssured.config()
.encoderConfig(EncoderConfig.encoderConfig()
.encodeContentTypeAs("x-www-form-urlencoded",
ContentType.URLENC)))
.contentType(ContentType.URLENC.withCharset("UTF-8"))
.formParam("grant_type", *)
.formParam("code", *)
.formParam("client_id",*)
.when().log().all()
.then().log().all().request()
request.post("/oauth2/token")`
我猜睡觉保证发布为Form Param而不是"x-www-form-urlencode"?
这是睡觉放心日志:`
Request method: POST
Request URI: ***
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: grant_type=***
code=***
client_id=***
Path params: <none>
Headers: Accept=image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap
Content-Type=application/x-www-form-urlencoded; charset=UTF-8
Cookies: <none>
Multiparts: <none>
Body: <none>
HTTP/1.1 405 Method Not Allowed
Content-Length: 61
Date: Tue, 30 Jan 2018 06:59:20 GMT
X-Correlationid: 5d155b6f-0d85-4775-5f50-82c397e5b44b
X-Smp-Log-Correlation-Id: 5d155b6f-0d85-4775-5f50-82c397e5b44b
X-Vcap-Request-Id: 5d155b6f-0d85-4775-5f50-82c397e5b44b
Only support Content-Type:application/x-www-form-urlencoded
` 这个问题把我逼疯了好几天。 请务必让我知道是否有其他方式发送x-www-form-urlencode参数或代码中所需的某些更新。
非常感谢!
推荐答案
Response response = RestAssured
.given()
.contentType("application/x-www-form-urlencoded; charset=utf-8")
.formParam("grant_type", "password")
.formParam("username", user_email)
.formParam("password", user_password)
.formParam("audience", audience)
.formParam("scope", "openid email")
.formParam("client_id", REGULAR_APP_CLIENT_ID)
.formParam("client_secret", REGULAR_APP_SECRET_ID)
.when()
.post(AUTH0_URL);
这篇关于如何发布睡觉保证的x-www-urlencode请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文