HttpClient client = new HttpClient(); PostMethod post = new PostMethod(url); byte[] b =json.toString().getBytes(); RequestEntity entity = new ByteArrayRequestEntity(b); post.setRequestEntity(entity); post.setRequestHeader("Content-Type", "application/octet-stream"); int code = client.executeMethod(post); String result=post.getResponseBodyAsString();
或者
DefaultHttpClient httpClient=new DefaultHttpClient(); HttpEntity httpEntity = new StringEntity(iq.toXML(), "UTF-8"); HttpPost httpPost = new HttpPost("http://******:7080/channel/send"); httpPost.setEntity(httpEntity); HttpResponse response = httpClient.execute(httpPost); InputStream is = response.getEntity().getContent(); BufferedReader in = new BufferedReader(new InputStreamReader(is)); StringBuffer buffer = new StringBuffer(); String line = ""; while ((line = in.readLine()) != null) { buffer.append(line); }
相关推荐
httpclient上传数据,通过httpclient在Android上实现上传数据
文档中详细演示了如何使用HttpClient4进行文件上传
httpClient post 上传图片 下载下来 修改下 上传和下载的uri
本功能支持文件上传 下载,支持请求流,支持JSON、XML请求,本版本是httpclient 4,其它jar包自行下载
文件上传 HttpClient
通过httpclient获取到JSON数据,展示到ListView通过httpclient获取到JSON数据,展示到ListView
httpclient3 httpclient4 上传文件 乱码问题
完整的上传实例包括图片和参数配置,可以通过该样例进行扩展使用
使用httpclient上传文件, CloseableHttpClient httpClient = HttpClientBuilder.create().build();
利用c# httpclient ,post json数据到web api
httpclient和RestfuL服务风格上传下载文件,可改为JAVA分布式系统进行交互,具体用法和改法详见代码里的注释
主要介绍了HttpClient通过Post上传文件的实例代码的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下
NULL 博文链接:https://username2.iteye.com/blog/2004550
java中跨项目使用httpclient实现数据交换
asp.net core3.1 webAPI对接企业微信上传临时素材,返回media_id. 来自于实际项目;
NULL 博文链接:https://wangwang-163-com.iteye.com/blog/728831
小小测试项目包含了4个知识点,其中包含了http协议向服务器传输数据的post和get方法,包含了httpclient传输方法,httpclient上传文件到服务器的方法,
使用HttpClient实现文件的上传所需lib
通过httpclient获取到JSON数据展示到ListView.zip
Ionic+Angular+Express实现前后端交互使用HttpClient发送get请求数据并加载显示示例代码