如何实现servlet接收客户端发来的http请求并返回
1个回答
展开全部
在servlet中通过request获取请求参数,通过response.getWriter().write("返回信息")返回
楼主,有个东东叫httpclient,是apache的一个子项目,传送门:,下面是示例:
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
List<NameValuePair> params = new ArrayList();
UrlEncodedFormEntity requestEntity;
requestEntity = new UrlEncodedFormEntity(params, "UTF-8");
(requestEntity);
HttpResponse response = client.execute(httppost);
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){}
client.getConnectionManager().shutdown();
楼主,有个东东叫httpclient,是apache的一个子项目,传送门:,下面是示例:
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
List<NameValuePair> params = new ArrayList();
UrlEncodedFormEntity requestEntity;
requestEntity = new UrlEncodedFormEntity(params, "UTF-8");
(requestEntity);
HttpResponse response = client.execute(httppost);
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){}
client.getConnectionManager().shutdown();
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询