httpclient 使用 httpmine

引用
https://blog.csdn.net/xiaojianpitt/article/details/6856536

http4.5之后的

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

引用

实现

httpClient4如何实现

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

HttpPosthttpPost=newHttpPost(url);

Log.debug("posturl:"+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");

MultipartEntitymutiEntity=newMultipartEntity();

Filefile=newFile("d:/photo.jpg");

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

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

httpPost.setEntity(mutiEntity);

HttpResponsehttpResponse=httpClient.execute(httpPost);

HttpEntityhttpEntity=httpResponse.getEntity();

Stringcontent=EntityUtils.toString(httpEntity);

引用

请求方式POST

请求示例:

https://hop.shrb.it/devportal/ws/file/upload

要求:

表单提交,表单数据类型为:multipart/form-dataURL:https://secapi.hulubank.com.cn/devportal/ws/file/upload?sysName=aaa&appID=bbb&filePath=ccc

相关推荐