Skip to content

Commit

Permalink
Merge pull request googleapis#24 from shinfan/master
Browse files Browse the repository at this point in the history
Fixed an issue that sendPostRequest() was not waiting for the response.
  • Loading branch information
shinfan committed Mar 10, 2016
2 parents cafe845 + 80b6097 commit 8a1d7a2
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -250,13 +251,18 @@ 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");
con.setDoOutput(true);
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;
}
}

0 comments on commit 8a1d7a2

Please sign in to comment.