我不确定这是否是您正在寻找的,但如果您想要做的只是在 Java 中发出 HTTP 请求,这应该可以解决问题:
HttpURLConnection urlConnection = null;
URL urlToRequest = new URL("http://yoursite.com/yourpage?key=val&key1=val1");
urlConnection = (HttpURLConnection) urlToRequest.openConnection();
urlConnection.setConnectTimeout(CONN_TIMEOUT);
urlConnection.setReadTimeout(READ_TIMEOUT);
// handle issues
int statusCode = urlConnection.getResponseCode();
if (statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
// handle unauthorized (if service requires user login)
} else if (statusCode != HttpURLConnection.HTTP_OK) {
// handle any other errors, like 404, 500,..
}
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
// Process response
用您自己的值和与您网站的 URL 相匹配的 URL 替换超时常量。您可以通过单击按钮以键/值对的形式将要发送的任何数据作为 URL 中的查询参数发送。