httpclient 使用 httpmine

阅读更多
引用
https://blog.csdn.net/xiaojianpitt/article/details/6856536


http 4.5之后的

https://blog.csdn.net/yanweihu/article/details/54410172
引用


实现
httpClient4如何实现
httpClient4使用http-mime.jar包的MultipartEntity实现,代码如下(为了简洁,处理了异常处理代码):

                           

HttpPost httpPost = newHttpPost(url);

Log.debug("post url:"+url);

httpPost.setHeader("User-Agent","SOHUWapRebot");

httpPost.setHeader("Accept-Language","zh-cn,zh;q=0.5");

httpPost.setHeader("Accept-Charset","GBK,utf-8;q=0.7,*;q=0.7");

httpPost.setHeader("Connection","keep-alive");

 

MultipartEntity mutiEntity = newMultipartEntity();

File file = new File("d:/photo.jpg");

mutiEntity.addPart("desc",new StringBody("美丽的西双版纳", Charset.forName("utf-8")));

mutiEntity.addPart("pic", newFileBody(file));

 

 

httpPost.setEntity(mutiEntity);

HttpResponse  httpResponse = httpClient.execute(httpPost);

HttpEntity httpEntity =  httpResponse.getEntity();

String content = EntityUtils.toString(httpEntity);



引用


请求方式POST
请求示例:
https://hop.shrb.it/devportal/ws/file/upload
要求:
表单提交,表单数据类型为:multipart/form-data URL: https://secapi.hulubank.com.cn/devportal/ws/file/upload?sysName=aaa&appID=bbb&filePath=ccc

你可能感兴趣的:(httpclient 使用 httpmine)