集成mailchimp(待完善)

调用get类型接口

private static String REST_API = "https://<dc>.api.mailchimp.com/3.0";

    //get 已通过
    public static void getAllResource() throws Exception {
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet request = new HttpGet(REST_API + "/lists");
        request.setHeader("Authorization", "apikey 你的apikey");
        HttpResponse response = httpClient.execute(request);
        String json = EntityUtils.toString(response.getEntity());
        logger.warn("\n\n" + json + "\n\n");
    }

在网上了找了一大推的httpclient的调用api的方法,最后发现原来github上已经有前辈集成了工具包,并且提供了maven依赖,但是因为楼主需要做批量的添加,删除操作,所有是自己下载了源码包去进行二次开发的,以下是github的链接

https://github.com/alexanderwe/bananaj

这个源码的Connection.java中的post方法是可以传html特殊字符的,但是put方法不可以,所以需要将do_put方法中的

httpput.setEntity(EntityBuilder.create().setText(put_string).build());

改为

        StringEntity entity = new StringEntity(post_string, "utf-8");
        entity.setContentEncoding("UTF-8");
        entity.setContentType("application/json");
        httppost.setEntity(entity);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值