17
Java - gửi các tham số HTTP thông qua phương thức POST một cách dễ dàng
Tôi đang sử dụng thành công mã này để gửi HTTPyêu cầu với một số tham số thông qua GETphương thức void sendRequest(String request) { // i.e.: request = "http://example.com/index.php?param1=a&param2=b&param3=c"; URL url = new URL(request); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setInstanceFollowRedirects(false); connection.setRequestMethod("GET"); connection.setRequestProperty("Content-Type", "text/plain"); connection.setRequestProperty("charset", "utf-8"); connection.connect(); } Bây …