httpclient 使用 httpmine
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
相关推荐
创建一个 HttpClient 实例,这个实例需要调用 Dispose 方法释放资源,这里使用了 using 语句。接着调用 GetAsync,给它传递要调用的方法的地址,向服务器发送 Get 请求。