首页 代理IP 代理IP示例代码 获取代理IP[Java]

获取代理IP示例代码[Java]

作者:xiezhongpian 阅读数:1397 上传时间:2017-05-09

获取代理IP

package api.jisuapi.proxy;

import api.util.HttpUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Get {

	public static final String APPKEY = "your_appkey_here";// 你的appkey
	public static final String URL = "https://api.jisuapi.com/proxy/get";
	public static final int num = 100;// 提取数量
	public static final String area = "";// 区域(多个用,隔开)
	public static final String areaex = "";// 排除区域(多个用,隔开)
	public static final String type = "";// 匿名(1高匿名,2匿名,3透明)
	public static final String port = "";// 端口(多个用,隔开)
	public static final String portex = "";// 排除端口(多个用,隔开)
	public static final String protocol = "";// 协议 1 HTTP, 2 HTTPS(也支持HTTP)

	public static void IPGet() {
		String result = null;
		String url = URL + "?num=" + num + "&area=" + area + "&areaex=" + areaex + "&type=" + type + "&port=" + port
				+ "&portex=" + portex + "&protocol=" + protocol + "&appkey=" + APPKEY;

		try {
			result = HttpUtil.sendGet(url, "utf-8");
			JSONObject json = JSONObject.fromObject(result);
			if (json.getInt("status") != 0) {
				System.out.println(json.getString("msg"));
			} else {
				JSONObject resultarr = json.optJSONObject("result");
				JSONArray list = resultarr.optJSONArray("list");
				for (int i = 0; i < list.size(); i++) {
					JSONObject obj = (JSONObject) list.opt(i);
					String ip = obj.getString("ip");
					String area = obj.getString("area");
					String anonymity = obj.getString("anonymity");
					String protocol = obj.getString("protocol");
					String speed = obj.getString("speed");
					System.out.println(ip + " " + area + " " + anonymity + " " + protocol + " " + speed);
				}
				String count = resultarr.getString("count");
				System.out.println(count);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}