首页 > 代码库 > java 模拟登陆 写给自己看
java 模拟登陆 写给自己看
package denglu; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.message.BasicNameValuePair; public class Tset { public void shiyan() throws ClientProtocolException, IOException{//获取页面信息 HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet("http://192.168.33.160:8088/login.html"); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); String html = EntityUtils.toString(entity, "GBK"); httpget.releaseConnection(); System.out.println(html); } public void login() throws ClientProtocolException, IOException{ HttpPost httppost = new HttpPost("http://192.168.33.160:8088/login.html"); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("name", "admin")); params.add(new BasicNameValuePair("password", "admin")); httppost.setEntity(new UrlEncodedFormEntity(params)); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(httppost); httppost.releaseConnection(); //验证是否登陆成功 如果失败是打不开登陆后的页面的 //String memberpage = "http://192.168.33.160:8088/hlslist.html"; String url="http://192.168.33.160:8088/api/addHLSList?n1=shiyan7&n2=rtsp://admin:admin@192.168.33.88:554/1.sdp&n3=0"; HttpGet httpget = new HttpGet(url); response = httpclient.execute(httpget); // 必须是同一个HttpClient! HttpEntity entity = response.getEntity(); String html = EntityUtils.toString(entity, "GBK"); httpget.releaseConnection(); System.out.println(html); } public static void main(String[] args) throws ClientProtocolException, IOException{ Tset t=new Tset(); t.login(); } }
java 模拟登陆 写给自己看
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。