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();
}
}