百度风云榜实时热点API

版权声明:本文为博主原创文章,可供所有开发人员随意转载使用! https://blog.csdn.net/SoumnsJ/article/details/85229399

postman请求:

请求详情:

请求地址:https://api.shenjian.io/?appid=205f4451a9d9d71d62c186d609066e89

请求参数:

请求方式:GET/POST

JAVA代码实现:

String appid="205f4451a9d9d71d62c186d609066e89"

String httpUrl = "https://api.shenjian.io/";

String httpArg = "appid="+appid;

String jsonResult = request(httpUrl, httpArg);

System.out.println(jsonResult);

/**

* @param urlAll

* :请求接口

* @param httpArg

* :参数

* @return 返回结果

*/

public static String request(String httpUrl, String httpArg) {

BufferedReader reader = null;

String result = null;

StringBuffer sbf = new StringBuffer();

httpUrl = httpUrl + "?" + httpArg;

try {

URL url = new URL(httpUrl);

HttpURLConnection connection = (HttpURLConnection) url.openConnection();

connection.setRequestMethod("GET");

connection.setRequestProperty("charset", "utf-8");

connection.setRequestProperty("Accept-Encoding", "gzip");

connection.connect();

InputStream is = new GZIPInputStream(connection.getInputStream());

reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));

String strRead = null;

while ((strRead = reader.readLine()) != null) {

sbf.append(strRead);

sbf.append("\r\n");

}

reader.close();

result = sbf.toString();

} catch (Exception e) {

e.printStackTrace();

}

return result;

}

猜你喜欢

转载自blog.csdn.net/SoumnsJ/article/details/85229399
今日推荐