【问题标题】:Convert String (Json) to Rest Assured Response将字符串 (Json) 转换为放心响应
【发布时间】:2016-09-22 20:16:10
【问题描述】:

我有一个 JSON 正文作为 Java String。我想将此String 转换为RestAssured Response。这可能吗?

或者

是否可以将 apache HttpResponse 转换为 RestAssured Response

HttpClient httpClient = HttpClientBuilder.create().build();
            HttpPost httpPost = new HttpPost(url);
            org.apache.http.entity.StringEntity entity = new org.apache.http.entity.StringEntity(body);
            httpPost.setEntity(entity);
            httpPost.setHeader("Accept", "application/json");
            httpPost.setHeader("Content-type", "application/json");
            HttpResponse httpResponse = httpClient.execute(httpPost);

我想将httpResponse 转换为RestAssured Response

【问题讨论】:

    标签: java json httpclient httpresponse rest-assured


    【解决方案1】:

    Response Javadoc 表示“REST Assured 发出的请求的响应。”。所以,不,我认为这不可能。无论如何,我会用RestAssurred 提出请求,我觉得更容易。

    参考:http://static.javadoc.io/com.jayway.restassured/rest-assured/1.2.3/com/jayway/restassured/response/Response.html

    【讨论】:

    • 问题是我收到handshake_failure 错误,即使在将我的RestAssured 版本升级到最新的3.0.1 并声称已解决该问题之后。我仍然看到它。这就是我使用HttpResponse 的原因
    • @user1629109 你能用那个错误的完整堆栈跟踪更新你的问题吗?或者为它发布一个新问题?听起来这就是你真正想要解决的问题。
    • 感谢您的回复。这正是我要解决的问题 github.com/rest-assured/rest-assured/issues/548 。 RestAssured 缺乏 SNI 支持。因此,当我尝试连接已实现 SNI 的服务器时,我遇到了握手失败错误。但是 Apache HttpClient 就像一个魅力
    猜你喜欢
    • 2012-10-14
    • 2019-11-19
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-19
    • 2017-01-17
    相关资源
    最近更新 更多