我假設您發佈Google Spreadsheet的方法類似於this question的回答。
我建議您使用稱爲okhttp的第三方庫。
okhttp是可靠,易於使用,它也有幾個附加功能。
以下是示例代碼。希望這會有所幫助。
// perpare httpclient
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(20, TimeUnit.SECONDS);
client.setReadTimeout(20, TimeUnit.SECONDS);
// prepare post params
RequestBody body = new FormEncodingBuilder()
.add("entry.0.single", cardOneURL)
.add("entry.1.single", outcome)
.add("entry.2.single", cardTwoURL)
.build();
// prepare request
Request request = new Request.Builder()
.url("https://spreadsheets.google.com/spreadsheet/your_spreadsheet")
.post(body)
.build();
try {
client.newCall(request).execute(); // send your request
} catch (Exception ex) {
// do something
}