【问题标题】:Getting error code 503 with Rest Assured GET method使用 Rest Assured GET 方法获取错误代码 503
【发布时间】:2019-12-05 21:27:43
【问题描述】:

使用放心的 GET 方法时,我收到错误代码 503。这是代码。

RequestSpecification request = RestAssured.given();
Response post = request.log().all().relaxedHTTPSValidation().get(url);

它给了我 503 错误。 相同的 API 在 Postman 中运行良好。请提出建议。

【问题讨论】:

  • 5xx 是一个服务器问题,如果它在 Postman 中工作正常,但在 [rest-assured] 调用中不能正常工作,最好检查服务器日志中是否存在特定错误。还请发布邮递员详细信息,以检查请求构造方式是否存在任何差异。
  • 在 elb 服务器中调试后问题解决。问题是由于主机头值造成的。

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


【解决方案1】:

您的代码需要更正如下。

  /*
 * We can parameterize it using baseURI and basePath and send a request to get a customer using ID      
 */
        RestAssured.baseURI = "http://parabank.parasoft.com/";
        RestAssured.basePath = "parabank/services/bank/customers";  

        //For the request You can define the setup values which can be  reuse  .
        RequestSpecBuilder reqbuild=new RequestSpecBuilder();
        //Adding values like path parameters
        reqbuild.addPathParam("customers", "12212");
        //Add content type
        reqbuild.setContentType(ContentType.JSON);// or reqbuild.setContentType("application/json; charset=UTF-8" );
        //After that build it
        requestSpecfication=reqbuild.build()

given().spec(requestSpecfication).when().get("{customers}/").then().log().all();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-20
    • 2021-06-05
    • 1970-01-01
    • 2020-03-10
    • 2017-08-20
    • 2018-11-04
    • 2019-07-04
    • 2015-04-16
    相关资源
    最近更新 更多