在Java中,可以使用各種庫來獲取FormData數據。以下是一些常用的方法:
String username = request.getParameter("username");
String password = request.getParameter("password");
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://example.com");
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("username", "admin"));
params.add(new BasicNameValuePair("password", "123456"));
httpPost.setEntity(new UrlEncodedFormEntity(params));
CloseableHttpResponse response = client.execute(httpPost);
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity);
這些是獲取FormData數據的一些常用方法,你可以根據自己的需求選擇合適的方法來使用。