httpclientpost怎么使用httpclient post接收xml文件

httpclientpost  时间:2021-01-06  阅读:()

如何使用httpclient进行post请求

http请求传递的都是字符串。

这种情况一般使用xml为信息载体。

把java类转成xml, client得到xml再转成java类。

UserDTO user = new UserDTO(); ...//填充user XStream xstream = new XStream();//使用xstream转换pojo和xml字符串 // HttpPost连接...

HttpClient的Post方法要怎么使用?

HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(URL); List params = new ArrayList(); String toServer = youdata; params.add(new BasicNameValuePair("par", "toServer")); try { HttpEntity httpentity = new UrlEncodedFormEntity(params,"gb2312"); post.setEntity(httpentity); HttpResponse httpResponse = client.execute(post); if(httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { //处理POST返回回来的数据 } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }

httpclient中怎么使用post方法获取html的源码

public void clientPost() { String httpUrl="http://10.0.2.2:8080/JDemo/android/httpget2.jsp"; // HttpPost连接对象 HttpPost httpRequest=new HttpPost(httpUrl); //使用NameValuePair来保存要传递的Post参数 List params=new ArrayList(); //添加要传递的参数 params.add(new BasicNameValuePair("par","HTTP_Client_android_Post")); try { //设置字符集 HttpEntity httpentity=new UrlEncodedFormEntity(params,"gb2312"); //请求httpRequest httpRequest.setEntity(httpentity); //取得HttpClient对象 HttpClient httpclient=new DefaultHttpClient(); //请求HttpCLient,取得HttpResponse HttpResponse httpResponse=httpclient.execute(httpRequest); //请求成功 if(httpResponse.getStatusLine().getStatusCode()==HttpStatus.SC_OK) { //取得返回的字符串 String strResult=EntityUtils.toString(httpResponse.getEntity()); text1.setText(strResult.trim()); }else { text1.setText("请求错误!"); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch(Exception e) { text1.setText(e.getMessage().toString()); } } 纯手打,望采纳!

httpclient中post命令需要的参数从哪里得知?

对应的变量名你还是问问网站的工作人员吧,点击某个按钮你可以将信息先传到servlet,在servlet里面引用httpclient,很简单的。

具体还是参考一下HttpClient类的executeMethod方法吧,网上一堆,多多练习,祝你好运

httpclient可以post文件吗

//?Java?使用HttpClient?post文件实现代码 import?java.io.File; .apache.http.HttpEntity; .apache.http.HttpResponse; .apache.http.HttpVersion; .apache.http.client.HttpClient; .apache.http.client.methods.HttpPost; .apache.http.entity.mime.MultipartEntity; .apache.http.entity.mime.content.ContentBody; .apache.http.entity.mime.content.FileBody; .apache.http.impl.client.DefaultHttpClient; .apache.http.params.CoreProtocolPNames; .apache.http.util.EntityUtils; public?class?PostFile?{ ??public?static?void?main(String[]?args)?throws?Exception?{ ????HttpClient?httpclient?=?new?DefaultHttpClient(); ????httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,?HttpVersion.HTTP_1_1); ????HttpPost?httppost?=?new?HttpPost("http://localhost:9001/upload.php"); ????File?file?=?new?File("c:/TRASH/zaba_1.jpg"); ????MultipartEntity?mpEntity?=?new?MultipartEntity(); ????ContentBody?cbFile?=?new?FileBody(file,?"image/jpeg"); ????mpEntity.addPart("userfile",?cbFile); ????httppost.setEntity(mpEntity); ????System.out.println("executing?request?"?+?httppost.getRequestLine()); ????HttpResponse?response?=?httpclient.execute(httppost); ????HttpEntity?resEntity?=?response.getEntity(); ????System.out.println(response.getStatusLine()); ????if?(resEntity?!=?null)?{ ??????System.out.println(EntityUtils.toString(resEntity)); ????} ????if?(resEntity?!=?null)?{ ??????resEntity.consumeContent(); ????} ????httpclient.getConnectionManager().shutdown(); ??} }

怎么使用httpclient post接收xml文件

现在sql2005可以直接接受xml数据,只要你逻辑层,把表示层数据构造好xml文件,直接提交到相应的xml字段就可以 using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Net; using System.Web; namespace Deerchao.Utility { public class HttpClient { #region fields private bool keepContext; private string defaultLanguage = "zh-CN"; private Encoding defaultEncoding = Encoding.UTF8; private string ept = "*/*"; private string userAgent = "Mozilla/4.0 patible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"; private HttpVerb verb = HttpVerb.GET; private HttpClientContext context; private readonly List files = new List(); private readonly Dictionary postingData = new Dictionary(); private string url; private WebHeaderCollection responseHeaders; private int startPoint; private int endPoint; #endregion

10gbiz七月活动首月半价$2.36/月: 香港/洛杉矶CN2 GIA VPS

10gbiz怎么样?10gbiz 美国万兆带宽供应商,主打美国直连大带宽,真实硬防。除美国外还提供线路非常优质的香港、日本等数据中心可供选择,全部机房均支持增加独立硬防。洛杉矶特色线路去程三网直连(电信、联通、移动)回程CN2 GIA优化,全天低延迟。中国大陆访问质量优秀,最多可增加至600G硬防。香港七星级网络,去程回程均为电信CN2 GIA+联通+移动,大陆访问相较其他香港GIA线路平均速度更...

knownhost西雅图/亚特兰大/阿姆斯特丹$5/月,2个IP1G内存/1核/20gSSD/1T流量

美国知名管理型主机公司,2006年运作至今,虚拟主机、VPS、云服务器、独立服务器等业务全部采用“managed”,也就是人工参与度高,很多事情都可以人工帮你处理,不过一直以来价格也贵。也不知道knownhost什么时候开始运作无管理型业务的,估计是为了扩展市场吧,反正是出来较长时间了。闲来无事,那就给大家介绍下“unmanaged VPS”,也就是无管理型VPS,低至5美元/月,基于KVM虚拟,...

盘点618年中大促中这款云服务器/VPS主机相对值得选择

昨天有在"盘点2021年主流云服务器商家618年中大促活动"文章中整理到当前年中大促618活动期间的一些国内国外的云服务商的促销活动,相对来说每年年中和年末的活动力度还是蛮大的,唯独就是活动太过于密集,而且商家比较多,导致我们很多新人不懂如何选择,当然对于我们这些老油条还是会选择的,估计没有比我们更聪明的进行薅爆款新人活动。有网友提到,是否可以整理一篇当前的这些活动商家中的促销产品。哪些商家哪款产...

httpclientpost为你推荐
苹果x和xr哪个好苹果x和苹果xr买哪个好杀毒软件哪个好什么杀毒软件比较好呢??少儿英语哪个好少儿英语哪种的好?少儿英语哪个好少儿英语哪个好少儿英语哪个好少儿英语,那个好一些?杰士邦和杜蕾斯哪个好杰士邦的超薄款跟杜蕾斯的超薄款,哪个舒服点?牡丹江教育云空间登录云端学习如何登录?网页qq空间登录为什么我用网页登录QQ空间时,没有登录界面,直接进去一个QQ空间,请问是怎么回事?dns服务器故障DNS服务异常是什么意思360云盘36t现在360云盘不能免费领取36T了吗?活动到期了?怎么领取更多空间?详细步骤和地址。
域名服务商 域名是什么 成都主机租用 cn域名个人注册 hawkhost 台湾服务器 免费cdn加速 iis安装教程 免费全能空间 阿里云浏览器 服务器维护方案 老左来了 双线主机 美国免费空间 电信虚拟主机 国内空间 广东服务器托管 xshell5注册码 装修瓦工培训 更多