首先使用java代码实现网络的连接。
定义 HttpUtil类。
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpUtil {
public static String getJsonContent(String url_path) {
InputStream inputStream = null;
try {
URL url = new URL(url_path);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setConnectTimeout(3000);
connection.setRequestMethod("GET");
connection.setDoInput(true);
int code = connection.getResponseCode();
System.out.println("code=================" + code);
if (code == 200) {
inputStream = connection.getInputStream();
return chageInputStream(inputStream);// 调用下面的方法,将流变为字符返回。
}
} catch (IOException e) {
// TODO Auto-generated