调用http接口 示例(restful风格)
1、调用别的平台丝袜哥http的接口–小记。
备注:
(1)调用的是path接口,
(2)密码是64位转码生成的。
(3)调用时要开通本地到平台的端口,才能调用到。
(4)如果调用的是域名,hosts里要配置平台映射地址,生产上也一样。
String jsonStr = ""; HashMaphs = null; String path = "https://www.yzsite.cn/"; DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(path); httpGet.setHeader("Authorization","aXRudjp=="); HttpResponse response = httpClient.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200){ HttpEntity entity = response.getEntity(); InsputStream input = entity.getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(input)); String str = br.readLine(); java.lang.String result = new java.lang.String(str.getBytes("gbk")); jsonStr = result; br.close(); input.close(); }else{ System.out.println(false); } return jsonStr;