JAVA调用接口获取数据
Posted 四叶草的眼泪
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA调用接口获取数据相关的知识,希望对你有一定的参考价值。
package com.zving.zzfw.bl; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; import com.zving.appapi.util.HttpClientUtil; import com.zving.framework.json.JSONObject; /** * @author Clover * 登录用户同步题库类 */ public class TiKuMemberSyc { public final static String url = "http://tk.ipmph.com/exam/a/api/asyncUser"; public static HttpClient httpclient; public static PostMethod post; public static void memberSyc(String userName) { JSONObject json = new JSONObject(); json.put("loginName", userName); try { httpclient = HttpClientUtil.getInstance(); //httpclient.getParams().setContentCharset("UTF-8"); post = new PostMethod(url); post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8"); post.addParameter("json", json.toJSONString()); @SuppressWarnings("unused") int status = httpclient.executeMethod(post); String dest = post.getResponseBodyAsString(); System.out.println(dest); } catch (Exception e) { e.printStackTrace(); } } }
以上是关于JAVA调用接口获取数据的主要内容,如果未能解决你的问题,请参考以下文章