String url="http://www.baidu.com/";
String get="";
int code=0;
try{
get = "email=" + URLEncoder.encode("e-mail", "UTF-8") + "&password=" + "password";
URL l_url = new java.net.URL(url);
HttpURLConnection l_connection = (java.net.HttpURLConnection) l_url.openConnection();
l_connection.setRequestProperty("Connection","aaa");
l_connection.setRequestProperty("User-Agent","123");
l_connection.connect();
l_connection = (HttpURLConnection) l_url.openConnection ();
l_connection.setFollowRedirects(true);
l_connection.setInstanceFollowRedirects(true);
l_connection.setAllowUserInteraction(true);
l_connection.setUseCaches(true);
l_connection.setRequestMethod("GET");
l_connection.usingProxy();
l_connection.setDoInput(true);
code = l_connection.getResponseCode();
System.out.println("~~~~~"+code);
String headName,headValue;
for (int i = 0; (headValue = l_connection.getHeaderField(i)) != null; i++) {
headName = l_connection.getHeaderFieldKey(i);
if (headValue!=null)
System.out.println("headRetParam:"+l_connection.getHeaderFieldKey(i)+" = " +headValue);
}
l_connection.disconnect();
l_connection = null;
l_url = null;
###########################################################################
为什么 l_connection.setRequestProperty("Connection","aaa");
这样设置,但是在返回的信息头部取的时候却没有Connection这项参数呢?
String get="";
int code=0;
try{
get = "email=" + URLEncoder.encode("e-mail", "UTF-8") + "&password=" + "password";
URL l_url = new java.net.URL(url);
HttpURLConnection l_connection = (java.net.HttpURLConnection) l_url.openConnection();
l_connection.setRequestProperty("Connection","aaa");
l_connection.setRequestProperty("User-Agent","123");
l_connection.connect();
l_connection = (HttpURLConnection) l_url.openConnection ();
l_connection.setFollowRedirects(true);
l_connection.setInstanceFollowRedirects(true);
l_connection.setAllowUserInteraction(true);
l_connection.setUseCaches(true);
l_connection.setRequestMethod("GET");
l_connection.usingProxy();
l_connection.setDoInput(true);
code = l_connection.getResponseCode();
System.out.println("~~~~~"+code);
String headName,headValue;
for (int i = 0; (headValue = l_connection.getHeaderField(i)) != null; i++) {
headName = l_connection.getHeaderFieldKey(i);
if (headValue!=null)
System.out.println("headRetParam:"+l_connection.getHeaderFieldKey(i)+" = " +headValue);
}
l_connection.disconnect();
l_connection = null;
l_url = null;
###########################################################################
为什么 l_connection.setRequestProperty("Connection","aaa");
这样设置,但是在返回的信息头部取的时候却没有Connection这项参数呢?
l_connection.setRequestProperty("User-Agent","123");是你写给baidu的,baidu不会再返回给你吧。