集成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);

猜你喜欢

转载自blog.csdn.net/k_clound/article/details/80251693