
朋友作手机号码生意,须要按期修改大量手机号服务密码,让我帮忙写程序。。。html
好吧,开始动工,计划从本地txt文件读取格式化数据,而后用程序去批量提交。java
当仁不让的用httpclient了。bootstrap
先分析须要哪些表单数据app
随便填写表单,点击修改,跳转到eclipse

查看提交数据,参照html表单,肯定提交的数据ide

好了,需求以及清楚了,那么下面开始ui
第一步:读取号码信息this

本地文本格式化成这样,手机号码----旧密码----新密码;spa
/**
* 读取15151433862----123456文档
* @param f
*/
private static void findContent(File f){
String line = null;
try {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(f), "gbk"));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
line = br.readLine();
while(line != null){
//读取一行记录,发送http请求
String[] strArr = line.split("----");
//System.out.println(strArr[0] +"======="+ strArr[1]+"======="+strArr[2]);
try {
modify(strArr[0],strArr[1],strArr[2]);
} catch (Exception e) {
e.printStackTrace();
}
line = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
读取数据后,调用modif()方法逐行修改,命令行
httpClient更新就是快,网上一大堆3.0之前的老版本,开源项目都是与时俱进的,官网老版本早就下架,

乖乖下载开发包,参考指导,写了下面这么一段,好在需求不复杂,等有时间把4.3的tutorial仔细看看
//发送http请求
private static void modify(String mobile,String oldPwd,String newPwd) throws Exception{
//得到HttpClient实例
CloseableHttpClient httpclient = HttpClients.createDefault();
URI uri = new URIBuilder()
.setScheme("http")
.setHost("wap.js.10086.cn")
.setPath("/actionDispatcher.do")
// .setParameter("mobile", "15161471125")
// .setParameter("oldPwd", "123111")
// .setParameter("newPwd", "123333")
// .setParameter("newPwdConfirm", "123333")
.setParameter("mobile", mobile)
.setParameter("oldPwd", oldPwd)
.setParameter("newPwd", newPwd)
.setParameter("newPwdConfirm", newPwd)
.setParameter("busiNum", "MMFW_MMXG")
.setParameter("checkOld", "1")
.setParameter("ver", "s")
.setParameter("operType", "4")
.setParameter("pageNum", "MMFW_MMXG")
.setParameter("confirm_isConfirm", "1")
.setParameter("fee", "")
.build();
HttpGet httpget = new HttpGet(uri);
System.out.println(httpget.getURI());
CloseableHttpResponse response = httpclient.execute(httpget);
System.out.println(response.toString());
try {
} finally {
response.close();
}
}
public static void main(String[] args) throws Exception {
File filename = new File("D:/号码.txt");
findContent(filename);
}
好了,大功告成,跑一下是能够的,
第三步,导出jar包,这里遇到些问题,百度了下,
为何export-->runnable jar file的launch configuration没有东西能够选择?
对于这个问题,网上答案少之又少,我来制造些内容吧。
为 什么MyEclipse8.5的export-->runnable jar file-->的launch configuration里面没有能够选择的东西了,实际上是要把你要打包成jar文件的工程的main方法运行一次,好比main方法在A类里,运行一 次A就有了
我是看见下面这段,试了一下弄出来的,喜欢的人仔细研究一下 Creating a Java application launch configuration
When you choose Run >Run As >Java Application to launch your class, you are running your class using a generic Java Application launch configuration that derives most of the launch parameters from your Java project and your workbench preferences. In some cases, you will want to override the derived parameters or specify additional arguments.
You do this by creating your own Java Application launch configuration.
- Select or from the workbench menu bar. This opens a dialog that lets you create, modify, and delete launch configurations of different types.
- Select Java Application in the left hand list of launch configuration types, and press the New button in the toolbar. This will create a new launch configuration for a Java application. The tabs on the right hand side allow you control specific aspects of the launch.
- The Main tab defines the class to be launched. Enter the name of the project containing the class to launch in the project field, and the fully qualified name of the main class in the Main class field. Check the Stop in main checkbox if you want the program to stop in the main method whenever the program is launched in debug mode.
Note: You do not have to specify a project, but doing so allows a default classpath, source lookup path, and JRE to be chosen.
- The Arguments tab defines the arguments to be passed to the application and to the virtual machine (if any). You can also specify the working directory to be used by the launched application.
- The JRE tab defines the JRE used to run or debug the application. You can select a JRE from the already defined JREs, or define a new JRE.
- The Classpath tab defines the location of class files used when running or debugging an application. By default, the user and bootstrap class locations are derived from the associated project's build path. You may override these settings here.
- The Source tab defines the location of source files used to display source when debugging a Java application. By default, these settings are derived from the associated project's build path. You may override these settings here.
- The Environment tab defines the environment variable values to use when running or debugging a Java application. By default, the environment is inherited from the Eclipse runtime. You may override or append to the inherited environment.
- The Common tab defines general information about the launch configuration. You may choose to store the launch configuration in a specific file and specify which perspectives become active when the launch configuration is launched.
成功导出runnable jar file,cmd打开命令行,找到jar包路径,运行 java -jar test.jar;

而后朋友不会java,,将jar包转成exe程序给他用
jar转exe转换器(jar2exe)(一款能够将jar文件转换成exe)下面的连接很详细
http://jingyan.baidu.com/article/00a07f38aad55182d128dc4c.html
开始的时候是打成jar,而后运行的时候报错
若是从 eclipse里export出的是 runnable jar file,那么个执行这个jar包的时候是不须要指明哪一个类的,直接这样执行 java -jar ch04.jar。缘由就是jar包中的MANIFEST.MF内容不一样。 runnable jar包中指明哪一个类先执行,因此你能够用 java -jar ch04.jar来执行你想要执行的代码,而没必要指明具体哪一个类。这个你能够打开 jar包查看MANIFEST.MF的区别,一目了然。
生成runnable jar file时,有两个选项,Extract required libraries into generated JAR 和 package equired libraries into generated JAR。 前者是把你用到的.class 文件提取出来,后者则是把你所须要的全部jar包都打进一个包里。二者的MANIFEST.MF文件内容也有所不一样,这应该是eclipse形成 的,IDE 作了本身的事情,具体就不研究了。