public class QueryKuaiDiFetch {
public static final String QUERYURL = "http://www.kuaidi100.com/query?";
public static String setUrl(String logisticsCode, String logisticsNo) {
String temp = String.valueOf(Math.random());
StringBuilder sb = new StringBuilder(QUERYURL);
sb.append("tpye=").append(logisticsCode).append("&");
sb.append("postid=").append(logisticsNo).append("&");
sb.append("temp=").append(temp);
return sb.toString();
}
public static String queryData(String num, Integer com) {
String line = "";
String temp = String.valueOf(Math.random());
String logisticsCode = "";
if (com == 0) {
logisticsCode = "shentong";
} else {
logisticsCode = "zhongtong";
}
String url = "http://www.kuaidi100.com/query?type=" + logisticsCode + "&postid=" + num + "&temp=" + temp + "&order=asc";
try {
URL realURL = new URL(url);
HttpURLConnection conn = (HttpURLConnection) realURL.openConnection();
String ip = randIP();
conn.setRequestProperty("X-Forwarded-For", ip);
conn.setRequestProperty("HTTP_X_FORWARDED_FOR", ip);
conn.setRequestProperty("HTTP_CLIENT_IP", ip);
conn.setRequestProperty("REMOTE_ADDR", ip);
conn.setRequestProperty("Host", "");
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36");
conn.connect();
int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream inputStream = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
while ((line = reader.readLine()) != null) {
System.out.println(line);
return line;
}
reader.close();
conn.disconnect();
}
} catch (Exception e) {
e.printStackTrace();
}
return line;
}
public static String randIP() {
Random random = new Random(System.currentTimeMillis());
return (random.nextInt(255) + 1) + "." + (random.nextInt(255) + 1)
+ "." + (random.nextInt(255) + 1) + "."
+ (random.nextInt(255) + 1);
}
}
工作忙,但还是要记得点外卖哦
欢迎关注我的外卖公众号,领优惠红包!还有电影票、酒店、滴滴红包哦
我刚做的小程序哦,欢迎交流程序问题哦~