httpclient post
来源:互联网 发布:编程语言选择 编辑:程序博客网 时间:2024/06/10 08:37
package com.cstc.interfaces.hainan;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import com.cstc.common.JSONCommon;
import com.cstc.common.entity.IntefaceAddress;
public class TaxConsultation extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String imgCode = request.getParameter("randcode");
String checkCode = (String) request.getSession().getAttribute("checkCode");
if(imgCode.equalsIgnoreCase(checkCode)){
JSONCommon json = new JSONCommon();
String jsons=null;
IntefaceAddress ads=IntefaceAddress.getIntefaceAddress();
String url = ads.getUrl();
url +="/nszx/submitMobileOnlineQuestion.jhtml";
System.out.println(url);
Enumeration<String> map=request.getParameterNames();
HttpClient client=new HttpClient(); //三实例化 httpclient
client.getHttpConnectionManager().getParams().setSoTimeout(60000);
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8");
PostMethod method = new PostMethod(url); //实例化 postmethod 带url的
method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
while(map.hasMoreElements()){
String key=map.nextElement();
method.addParameter(key,request.getParameter(key)); //
}
try{
client.executeMethod(method);
jsons=new String(method.getResponseBodyAsString().getBytes("gb2312"));
}
catch(Exception e){
e.printStackTrace();
}finally{
method.releaseConnection();
}
json.writeJSON(response, jsons);
}
}
}
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import com.cstc.common.JSONCommon;
import com.cstc.common.entity.IntefaceAddress;
public class TaxConsultation extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String imgCode = request.getParameter("randcode");
String checkCode = (String) request.getSession().getAttribute("checkCode");
if(imgCode.equalsIgnoreCase(checkCode)){
JSONCommon json = new JSONCommon();
String jsons=null;
IntefaceAddress ads=IntefaceAddress.getIntefaceAddress();
String url = ads.getUrl();
url +="/nszx/submitMobileOnlineQuestion.jhtml";
System.out.println(url);
Enumeration<String> map=request.getParameterNames();
HttpClient client=new HttpClient(); //三实例化 httpclient
client.getHttpConnectionManager().getParams().setSoTimeout(60000);
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8");
PostMethod method = new PostMethod(url); //实例化 postmethod 带url的
method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
while(map.hasMoreElements()){
String key=map.nextElement();
method.addParameter(key,request.getParameter(key)); //
}
try{
client.executeMethod(method);
jsons=new String(method.getResponseBodyAsString().getBytes("gb2312"));
}
catch(Exception e){
e.printStackTrace();
}finally{
method.releaseConnection();
}
json.writeJSON(response, jsons);
}
}
}
0 0
- httpclient post
- httpclient post
- httpclient post
- HTTPCLIENT.POST
- HttpClient--HttpClient的Post请求
- get、post、httpclient-get、httpclient-post
- httpclient 登录 post
- java HttpClient Post实例
- HttpClient中的POST方法
- Httpclient发送POST请求
- HttpClient接口Post方式
- httpClient发送post请求
- httpClient get post 实例
- java HttpClient Post实例
- HttpClient get, post使用
- HttpClient Post提交实例
- Android HttpClient post MultipartEntity
- HttpClient发起post请求
- WGS84坐标系转为西安80坐标系的解决方式
- 在Android Studio中使用Android-PullToRefresh Library
- Android中的颜色对应的值
- adb常见问题--解决端口号被占用
- JAVA基础累积之HttpServletRequest
- httpclient post
- 英语小词典的安卓源码。
- CDH cm节点高可用方案
- mysql安装 + phpmyadmin 配置mysql管理界面
- 0.8147--Matlab产生的第一个随机数
- mysql日期
- Java对List中的对象进行排序
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- 未知图片大小的自动水平和垂直居中方法