java HttpClient Post实例
来源:互联网 发布:电信卡怎么设置4g网络 编辑:程序博客网 时间:2024/06/08 07:11
private void postMethod(String url) throws IOException
{
url = "http://www.newsmth.net/bbslogin2.php";
PostMethod postMethod = new PostMethod(url);
// 填入各个表单域的值
NameValuePair[] data = { new NameValuePair("id", "herrapfel"),new NameValuePair("passwd", "") };
// 将表单的值放入postMethod中
postMethod.setRequestBody(data);
// 执行postMethod
int statusCode = httpClient.executeMethod(postMethod);
System.out.println(" status code:" + statusCode);
// HttpClient对于要求接受后继服务的请求,象POST和PUT等不能自动处理转发
if(statusCode == HttpStatus.SC_OK)
{
StringBuffer contentBuffer = new StringBuffer();
InputStream in = postMethod.getResponseBodyAsStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in,postMethod.getResponseCharSet()));
String inputLine = null;
while((inputLine = reader.readLine()) != null)
{
contentBuffer.append(inputLine);
System.out.println("input line:"+ inputLine);
contentBuffer.append("/n");
}
in.close();
}
else if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY)
{
// 从头中取出转向的地址
Header locationHeader = postMethod.getResponseHeader("location");
String location = null;
if (locationHeader != null)
{
location = locationHeader.getValue();
System.out.println("The page was redirected to:" + location);
}
else
{
System.err.println("Location field value is null.");
}
}
- java HttpClient Post实例
- java HttpClient Post实例
- java HttpClient Post实例
- httpClient get post 实例
- HttpClient Post提交实例
- HttpClient post 请求实例
- HttpClient post 请求实例
- Java-HttpClient-Post
- Java--Http: HttpClient(post/get)
- java HttpClient进行POST请求
- JAVA实现httpClient实例
- Java HttpClient实例
- HttpClient(4.5) post get https 实例
- java httpclient发送post get 请求
- httpclient post提交报java.net.UnknownHostException
- java/android httpclient post/get用法
- java HttpClient get post请求 调用接口
- java httpclient 抓取网页 POST GET
- The Single Responsibility Principle
- 每一个有理想的程序员都应该读的一本书-《rework》
- Start from Yes
- leetcode 126: Word Ladder ll (uncompleted)
- Step Back and Automate, Automate, Automate
- java HttpClient Post实例
- JNI学习(5)(我是菜鸟)
- Take Advantage of Code Analysis Tools
- 俞敏洪一分钟励志演讲:
- Test for Required Behavior, not Incidental Behavior
- Android的permission大全
- 在交互细节上,Android 与 iOS 有哪些区别?
- PCB布板一些简易常用规则
- JNI学习(6)(我是菜鸟)