倾家荡产,请大家帮我写个java 代码 用java代码调用HttpClient API 来实现自动填写gmail表单的功能.拜托大家,十万火急用! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我写过, 不过忘记了具体细节, apache官网上很多例子啦, 一看就会了 冒死找出以前写的代码:import org.apache.commons.httpclient.Header;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.HttpStatus;import org.apache.commons.httpclient.NameValuePair;import org.apache.commons.httpclient.methods.PostMethod;public class DoLogin { public static void main(String[] args) { String loginUrl = "**************";//地址 doPost(loginUrl); } public static void doPost(String url) { HttpClient httpClient = new HttpClient(); String loginUrl = url;//登陆url try{ //登陆 PostMethod postMethod=new PostMethod(loginUrl); //登陆页面表单 NameValuePair username = new NameValuePair("name", "admin"); NameValuePair password = new NameValuePair("pwd", "admin"); postMethod.setRequestBody(new NameValuePair[] {username, password}); //打印返回状态 int statusCode=httpClient.executeMethod(postMethod); System.out.println(statusCode); String location = ""; String jsessionid = "";//打印返回的信息 String response = null; response = new String(postMethod.getResponseBodyAsString().getBytes("8859_1")); //打印结果页面 System.out.println(response); if(statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) { Header locationHeader = postMethod.getResponseHeader("location"); location = locationHeader.getValue(); System.out.println("The page will redirec to "+location); doPost(location); } postMethod.releaseConnection(); }catch(Exception err){ System.out.println(err.getMessage()); } }} "Save oould not be completed" 分析Gmail的html代码,然后把该填写的表单填写了再post过去就是了。。 那大家告诉我如何分析gmail的url和html也行,反正给我个简单的可以运行测试gmail的代码就行了 java 接口中的定义的变量为什么是 static final的? ThreadPoolExecutor线程池 java中转型问题 怎么让这段代码能读取中文啊 它只能读英文 一个关于acegi配置的问题,分不够马上加!!! 高分求算法:求助一个取得数组中的次大值的数据下标的JAVA的算法 怎么用Java实现简单的邮箱(SMTP和POP3协议) 面试遇到的题,请大神解答 紧急问题,马上需要,关于awt.Frame 这个论坛左侧的TreeView各个层之间如何实现没有空行? 实现一个去除整型数组中绝对值相同的数字.最后返回一个长度.(急面试题) Java
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;public class DoLogin {
public static void main(String[] args) {
String loginUrl = "**************";//地址
doPost(loginUrl);
}
public static void doPost(String url)
{
HttpClient httpClient = new HttpClient();
String loginUrl = url;//登陆url
try{
//登陆
PostMethod postMethod=new PostMethod(loginUrl);
//登陆页面表单
NameValuePair username = new NameValuePair("name", "admin");
NameValuePair password = new NameValuePair("pwd", "admin");
postMethod.setRequestBody(new NameValuePair[] {username, password});
//打印返回状态
int statusCode=httpClient.executeMethod(postMethod);
System.out.println(statusCode);
String location = "";
String jsessionid = "";
//打印返回的信息
String response = null;
response = new String(postMethod.getResponseBodyAsString().getBytes("8859_1")); //打印结果页面
System.out.println(response);
if(statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY)
{
Header locationHeader = postMethod.getResponseHeader("location");
location = locationHeader.getValue();
System.out.println("The page will redirec to "+location);
doPost(location);
}
postMethod.releaseConnection();
}catch(Exception err){
System.out.println(err.getMessage());
}
}
}