//获取一个Http连接的响应头
try {
// Create a URLConnection object for a URL
URL url = new URL("http://hostname:80");
URLConnection conn = url.openConnection();
// List all the response headers from the server.
// Note: The first call to getHeaderFieldKey() will implicit send
// the HTTP request to the server.
for (int i=0; ; i++) {
String headerName = conn.getHeaderFieldKey(i);
String headerValue = conn.getHeaderField(i);
if (headerName == null && headerValue == null) {
// No more headers
break;
}
if (headerName == null) {
// The header value contains the server's HTTP version
}
}
} catch (Exception e) {
}
try {
// Create a URLConnection object for a URL
URL url = new URL("http://hostname:80");
URLConnection conn = url.openConnection();
// List all the response headers from the server.
// Note: The first call to getHeaderFieldKey() will implicit send
// the HTTP request to the server.
for (int i=0; ; i++) {
String headerName = conn.getHeaderFieldKey(i);
String headerValue = conn.getHeaderField(i);
if (headerName == null && headerValue == null) {
// No more headers
break;
}
if (headerName == null) {
// The header value contains the server's HTTP version
}
}
} catch (Exception e) {
}
String password = "2222";
String httpUrl = "http://localhost:8000/struts-test/httpAddUser";
try {
URL url = new URL(httpUrl + "?name="+name+"&password="+password);
HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
httpConn.setDoInput(true);
httpConn.setDoOutput(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
System.out.println(httpConn.getHeaderField("result"));
httpConn.disconnect();
} catch (Exception e) {
e.printStackTrace();
}现在是只有两个参数,所以用GET传递就可以了,如果有多个参数时候改用POST方式传递,参数不想放httpUrl后面,怎么把各个参数都传到请求的地址?