2011-12-2
ubuntu系统root默认密码,每次开机会随机产生默认的root密码,修改的方式:
命令sudo passwd
输入、确认新密码
使用httpclient构建post请求的方法:
??? ?? String response = null; HttpClient client = null; PostMethod method = null;? try { client = new HttpClient(); //初始化 HttpClient client.getHostConfiguration().setHost("localhost", port); method = new PostMethod(url); //初始化 Http方法 POST,url中不包含参数信息,通过一下代码设置参数?????????????? method.setParameter("name", "a"); method.addParameter(new NameValuePair("sex","b")); ? ? method.addParameter(new NameValuePair("location","c")); ? ? method.addParameter(new NameValuePair("textarea1",new String(text.getBytes("utf-8"),"iso-8859-1")));????//防止乱码 text为类中的静态变量,类型为String? ? ? ? ? ? ?? client.getParams().setParameter(HttpMethodParams.USER_AGENT,"Mozilla/5.0 Firefox/3.5.2"); //将程序伪装为firefox client.executeMethod(method); //执行 POST 方法 if (method.getStatusCode() == HttpStatus.SC_OK) { //方法执行结果是否正常? InputStream inputStream = method.getResponseBodyAsStream(); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); StringBuffer stringBuffer = new StringBuffer(); String str= ""; while((str = br.readLine()) != null){ stringBuffer .append(str ); response=stringBuffer.toString(); } }//将网页保存为String else if (method.getStatusCode() == 404) return null; } catch (Exception e) { e.printStackTrace(); System.out.println("===== Timed Out ====="); } method.releaseConnection();
?与GET方法的区别,get方法的url,是通过method的setMethod方法设置,并且其中包含参数的传递。