1

我正在尝试使用“放心”来访问 API,这是一个带有表单参数客户端 ID、用户和密码的 POST 请求。和多个标题。

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

Response res =    
given().
        .header("Accept", "application/json")

        .header("Content-Type", "application/x-www-form-urlencoded")
        .header("channel","")
        .formParam("grant_type", "password")
        .formParam("client_id", "")
        .formParam("secret", "")
        .formParam("userId", "")
        .formParam("password","").

        when()
            .post("/apiname");
            System.out.println(res.body().asString());

返回类型为 json。

同样的事情也在 PostMan 上工作。请在这方面提供帮助。

4

1 回答 1

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");
于 2018-01-18T08:25:36.413 回答