【问题标题】:How to pass content type "application/x-www-form-urlencoded" with rest assured如何放心地传递内容类型“application/x-www-form-urlencoded”
【发布时间】:2018-06-24 20:02:39
【问题描述】:

我正在尝试使用“放心”来访问 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 也是如此。请帮忙。

【问题讨论】:

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


    【解决方案1】:

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

    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");
    

    【讨论】:

      猜你喜欢
      • 2021-02-03
      • 2015-04-02
      • 1970-01-01
      • 2019-09-12
      • 2020-04-21
      • 1970-01-01
      • 2017-08-26
      • 1970-01-01
      相关资源
      最近更新 更多