import org.httpz.HttpClient; public class MyHttpClient { private HttpClient httpClient; public MyHttpClient() { this.httpClient = new HttpClient(); } } import org.httpz.Request; public class MyHttpClient { private HttpClient httpClient; // ... public void makeHttpRequest() { String url = "https://example.com/api"; String requestBody = "{\"key\":\"value\"}"; Request request = new Request(url) .body(requestBody) .method("POST") .header("Content-Type", "application/json"); String response = httpClient.send(request).asString(); } // ... } import org.json.JSONObject; public class MyHttpClient { private HttpClient httpClient; // ... public void makeHttpRequest() { // ... String response = httpClient.send(request).asString(); JSONObject jsonObject = new JSONObject(response); String value = jsonObject.getString("key"); System.out.println("Value: " + value); // ... } // ... } public class Main { public static void main(String[] args) { MyHttpClient myHttpClient = new MyHttpClient(); myHttpClient.makeHttpRequest(); } }


上一篇:
下一篇:
切换中文