http接口调用
来源:互联网 发布:北大青鸟软件培训中心 编辑:程序博客网 时间:2024/06/05 02:45
一httpclient调用http接口
public static String sendRequest(String url, Map<String, String> paras) { try { HttpClient httpClient = new HttpClient(); PostMethod httpPost = new PostMethod(url); if (null != paras && paras.size() > 0) { Iterator<String> iterator = paras.keySet().iterator(); List<Part> partList = new ArrayList<Part>(); while (iterator.hasNext()) { String key = iterator.next(); partList.add(new StringPart(key, paras.get(key), "UTF-8")); } Part[] parts = new Part[partList.size()]; parts = partList.toArray(parts); httpPost.setRequestEntity(new MultipartRequestEntity(parts, httpPost.getParams())); } int a = httpClient.executeMethod(httpPost); System.out.println(a); InputStream inputStream = httpPost.getResponseBodyAsStream(); StringBuffer postResult = new StringBuffer(); String readLine = null; BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); while ((readLine = reader.readLine()) != null) { postResult.append(readLine); } return postResult.toString(); } catch (HttpException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }
----------------------------------------微信接口开发----------------------------------------------------------------------//消息体带参数不是=?号形式 例如微信接口HttpUriRequest httpUriRequest = RequestBuilder.post().setUri("https://api.weixin.qq.com/cgi-bin/menu/create").addParameter("access_token", accessToken).setEntity(new StringEntity(json, Consts.UTF_8)).build();//上传文件public static WxMedia uploadTempMedia(String access_token, String type, File media) { FileBody fb = new FileBody(media); HttpEntity entity = MultipartEntityBuilder.create().addTextBody("access_token", access_token).addTextBody("type", type).addPart("media", fb).build(); HttpUriRequest httpUriRequest = RequestBuilder.post("https://api.weixin.qq.com/cgi-bin/media/upload").setEntity(entity).build(); return (WxMedia)JSON.parseObject(HttpUtil.getResponseString(httpUriRequest), WxMedia.class);}
0 0
- 调用http接口操作
- C#调用HTTP接口
- httpclient http接口调用
- java调用http接口
- http/https接口调用
- http接口调用
- java调用http接口
- C#调用HTTP接口
- 【Java】调用http接口
- C#调用HTTP接口
- java 调用http接口
- java调用http接口
- http接口调用
- PowerBuilder 调用http接口
- 7.调用HTTP接口
- java调用http接口
- http请求接口,http接口远程调用
- 如何调用一个http接口
- iOS 基础篇2—UIWindow简单介绍
- DEBUGGING AND OPTIMIZING MEMORY
- iOS UINavigationController代理方法实现自定义
- su: 无法设置用户ID: 资源暂时不可用
- HashSet和HashMap比较
- http接口调用
- IOS更改UITabBarItem的图片及字体颜色
- 关于Android的style和theme
- Memcache+Spring AOP
- C++中auto型的详细解释
- FZU 2236 第十四个目标(严格上升子序列个数 离散化 + 树状数组)
- Linux下查看文件和文件夹大小
- lua select(a,b)函数
- 反射访问方法