【发布时间】:2021-11-17 05:46:35
【问题描述】:
您好,我正在尝试使用 Kotlin 进行自动化 API 测试,现在我需要添加一个发布请求以生成令牌。 post 方法包含内容类型为 application/x-www-form-urlencoded 现在我需要以 x-www-form-urlencoded 格式传递正文。我们怎样才能做到这一点。
""类登录:PostRequest() {
override fun buildHttpRequestBuilder(): HttpRequest.Builder {
val httpRequestBuilder = super.buildHttpRequestBuilder()
httpRequestBuilder.header("Content-Type", "application/x-www-form-urlencoded")
return httpRequestBuilder
}
override fun buildUrl(): String {
return "URL"
}
override fun buildPostBody(): String {
val body = JSONObject().apply {
.field("grant_type", "client_credentials")"""
【问题讨论】:
标签: api kotlin generics testing web-api-testing