public static void main(String[] args) throws Exception, IOException {
String url = "http://localhost:8080/test.jsp";
PostMethod postMethod = new UTF8PostMethod(url);
//填入各个表单域的值
NameValuePair[] data = {
new NameValuePair("TEXT", "中文"),
};
//将表单的值放入postMethod中
postMethod.setRequestBody(data);
//执行postMethod
HttpClient httpClient = new HttpClient();
httpClient.executeMethod(postMethod);
}
//Inner class for UTF-8 support
public static class UTF8PostMethod extends PostMethod{
public UTF8PostMethod(String url){
super(url);
}
@Override
public String getRequestCharSet() {
//return super.getRequestCharSet();
return "UTF-8";
}
}
String url = "http://localhost:8080/test.jsp";
PostMethod postMethod = new UTF8PostMethod(url);
//填入各个表单域的值
NameValuePair[] data = {
new NameValuePair("TEXT", "中文"),
};
//将表单的值放入postMethod中
postMethod.setRequestBody(data);
//执行postMethod
HttpClient httpClient = new HttpClient();
httpClient.executeMethod(postMethod);
}
//Inner class for UTF-8 support
public static class UTF8PostMethod extends PostMethod{
public UTF8PostMethod(String url){
super(url);
}
@Override
public String getRequestCharSet() {
//return super.getRequestCharSet();
return "UTF-8";
}
}