如何写精华回答,获更多曝光?
发布
package chazhao;
import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.AppSigner;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;
import java.io.*;
import java.net.*;
public class chazhao {
public static void main(String[] args) throws IOException {
FileWriter fileWriter = new FileWriter("手机号码.txt");
String httpUrl = "http://gsd.api.bdymkt.com/sms";
String httpArg = "";
for (int i = 0; i < 9999; i++) {
if (i >= 1000) {
httpArg = "phone=135" + String.valueOf(i) + "0015";
} else if (i >= 100) {
httpArg = "phone=1350" + String.valueOf(i) + "0015";
} else if (i >= 10) {
httpArg = "phone=13500" + String.valueOf(i) + "0015";
} else {
httpArg = "phone=135000" + String.valueOf(i) + "0015";
}
String jsonResult = request(httpUrl, httpArg);
if (jsonResult.contains("上海")) {
fileWriter.write(httpArg + "\n\t");
}
}
fileWriter.flush();
fileWriter.close();
}
/**
* @param urlAll :请求接口
* @param httpArg :参数
* @return 返回结果
*/
public static String request(String httpUrl, String httpArg) {
BufferedReader reader = null;
String result = null;
StringBuffer sb = new StringBuffer();
httpUrl = httpUrl + "?" + httpArg;
try {
URL url = new URL(httpUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();//打开url连接
connection.setConnectTimeout(15000);//设置连接超时时间
connection.setReadTimeout(15000);//设置读取超时时间
connection.setRequestMethod("POST");//设置请求参数,即具体的http方法
// 填入apikey到HTTP header
connection.setRequestProperty("apikey", " *************");
connection.setDoOutput(true);//设置是否向httpUrlConnection输出;对于post请求,参数要放在http正问内,因此需要设置为true(默认情况下是false)
connection.setDoInput(true);//设置是否从httpUrlConnection读入,默认情况下是true
connection.connect();//调用connect连接远程资源
InputStream is = connection.getInputStream();//利用getInputStream()访问资源数据
BufferedReader reader1 = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String strRead = null;
while ((strRead = reader1.readLine()) != null) {
sb.append(strRead);
sb.append("\r\n");
}
reader.close();
result = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}