diff --git a/src/main/java/com/google/api/gax/testing/LocalServiceHelper.java b/src/main/java/com/google/api/gax/testing/LocalServiceHelper.java index 1e0f84639cd1..0d8f45d0d174 100644 --- a/src/main/java/com/google/api/gax/testing/LocalServiceHelper.java +++ b/src/main/java/com/google/api/gax/testing/LocalServiceHelper.java @@ -19,6 +19,7 @@ import static com.google.common.base.MoreObjects.firstNonNull; import com.google.common.base.Strings; +import com.google.common.io.CharStreams; import java.io.BufferedReader; import java.io.IOException; @@ -250,7 +251,7 @@ public void stop() throws IOException, InterruptedException { } } - public void sendPostRequest(String request) throws IOException { + public String sendPostRequest(String request) throws IOException { URL url = new URL("http", "localhost", this.port, request); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); @@ -258,5 +259,10 @@ public void sendPostRequest(String request) throws IOException { OutputStream out = con.getOutputStream(); out.write("".getBytes()); out.flush(); + + InputStream in = con.getInputStream(); + String response = CharStreams.toString(new InputStreamReader(con.getInputStream())); + in.close(); + return response; } }