0

如何使 HttpClientResponse 返回 InputStream 而不是 vertx.rx.Buffer?

HttpClientRequest req = client.requestAbs(HttpMethod.POST, endpointUrl);
        req.putHeader("Content-Type", "text/xml; charset=utf-8").
                putHeader("SOAPAction", "http://192.168.0.170/TT/BookingAPI/Search");

        req.toObservable().flatMap(resp -> {
            if (resp.statusCode() != HttpStatus.SC_OK) {
                throw new RuntimeException("Wrong status code " + resp.statusCode());
            }
            return resp.toObservable();
        }).subscribe(new Subscriber<InputStream>() {
            public void onNext(InputStream stream) {

// 默认实现为 Buffer,需要获取 InputStream 传递给 StaxReader。} 公共无效 onError(Throwable e) { }

            public void onCompleted() {
                System.out.println("Start at :"+ st +" End at :"+ System.currentTimeMillis()+"Time taken: " + (System.currentTimeMillis() - st));
            }
        });
        req.end(request);

    }
4

1 回答 1

0

你会把你的 Buffer 转换成 InputStream 吗 :)

Buffer buffer = ...;
ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer.getBytes());
于 2015-12-21T07:05:53.800 回答