使用doPost访问三方接口

    如果我们的app应用需要对接第三方服务接口,可以采用doPost方法,代码如下:

//获取章节详情信息
        public void testGetChapterDetail() throws IOException {
        String postUrl = "http://112.13.170.215:18443/cip-cas/getChapterDetail";
        Map<String, String> header = getHeader();
        JSONObject paramJson = new JSONObject();
        String requestSeq = "12345678123456781234567812345678";
        paramJson.put("requestSeq", requestSeq);
        paramJson.put("appId", APPID);
        paramJson.put("password", getPassword(requestSeq));
        paramJson.put("equipmentId", EQUIPMENT_ID);
        paramJson.put("userId", "18867103563");
        paramJson.put("chapterId", "408959988");//章节ID 
        paramJson.put("chapterQuality", "2");
        paramJson.put("actType", "0");
        System.out.println("请求参数:" + paramJson.toString());
        String reString = HttpUtils.doPost(postUrl, header, paramJson.toString());
        System.out.println(reString);

    }

    首先,需要postUrl、header和请求参数。其次,调用HttpUtils的doPost方法,得到返回的字符串,再对字符串进行处理。



猜你喜欢

转载自blog.csdn.net/a1165117473/article/details/79375107