如何放心地传递内容类型“application / x-www-form-urlencoded”

时间:2018-01-16 07:08:22

标签: rest api rest-assured rest-assured-jsonpath

我正在尝试使用Rest assured来命中API,这是一个带有表单参数客户端ID,用户和密码的POST请求。和多个标题。

我收到了415,不支持的媒体类型错误。我的代码是:

<div class="message-container" [innerHTML]="msg | emojis">
</div>

返回类型是json。

同样的事情是在PostMan上工作。请帮助。

1 个答案:

答案 0 :(得分:0)

请求规范中有属性用于配置内容类型。不确定如果我们必须明确定义它,但我使用下面给出的语法。

given()
            .header("Accept", "application/json")
            .contentType("application/x-www-form-urlencoded")
            .header("channel","")
            .formParam("grant_type", "password")
            .formParam("client_id", "")
            .formParam("secret", "")
            .formParam("userId", "")
            .formParam("password","").
                    when()
            .post("/apiname");
相关问题