1 回答

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊
您可以用來HttpURLConnection進(jìn)行 API 調(diào)用。
檢查響應(yīng)并相應(yīng)地觸發(fā)另一個(gè)呼叫。
像這樣的東西
public static void main(String[] args) throws IOException {
String response1 = sendGET("http://url1");
if(response1 != null && response1.contains("true")){
String response2 = sendGET("http://url2");
}
}
private static String sendGET(String url) throws IOException {
URL obj = new URL(url);
StringBuffer response = new StringBuffer();
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
System.out.println("GET Response Code :: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) { // success
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// print result
System.out.println(response.toString());
} else {
System.out.println("GET request not worked");
}
return response.toString();
}
添加回答
舉報(bào)