很多简单的接口就是直接一个URl的形式,
怎么调用?
HttpClient httpclient=null;
PostMethod post=null;
try{
httpclient = new HttpClient();
post = new PostMethod(SendUrl);
//设置编码方式
post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"gbk");
//添加参数
post.addParameter("LoginName",LoginName);
post.addParameter("Password", Password);
//执行
httpclient.executeMethod(post);
//接口返回信息
String info = new String(post.getResponseBody(),CHARSET);
System.out.println(info);
}catch (Exception e) {
e.printStackTrace();
}finally {
//关闭连接,释放资源
post.releaseConnection();
((SimpleHttpConnectionManager)httpclient.getHttpConnectionManager()).shutdown();
}
到此为止,主要为自己做备忘,同时方便有需要的人。呵呵!