java code to open and close h5 stream video features



import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.assertj.core.util.Lists;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

public class H5Service {

public static void main(String[] args) {
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
InputStream is = null;
String url = "http://你的路径/api/v1/ManualRecordStart?token=???&session=?????";

//封装请求参数
List<NameValuePair> params = Lists.newArrayList();
params.add(new BasicNameValuePair("cityEname", "henan"));
String str = "";
try {
//转换为键值对
EntityUtils.toString = str (new new UrlEncodedFormEntity (params, Consts.UTF_8));
System.out.println ( "str" + str);
// create a Get request
HttpGet httpGet = new HttpGet (url + + str "?");
// perform a get request,
response = httpClient.execute (HttpGet);
// get a response form
the HttpEntity = response.getEntity Entity ();
IF (Entity = null!) {
iS = entity.getContent ();
// convert word section input stream
the BufferedReader the BufferedReader br = new new (new new the InputStreamReader (IS, Consts.UTF_8));
the stringBuffer stringBuffer the stringBuffer new new = ();
String body = null;
while ((body = br.readLine()) != null) {
stringBuffer.append(body);
System.out.println(body);

}
String jsonBuffer = stringBuffer.toString();
JSONObject jo = new JSONObject(jsonBuffer);
System.out.println("路径是"+jo.get("strUrl"));

}
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
//关闭输入流,释放资源
if (is != null) {
{the try
is.close ();
} the catch (IOException E) {
e.printStackTrace ();
}
}
// consume substantial contents
IF (Response = null!) {
the try {
response.close ();
} the catch (IOException E) {
e.printStackTrace ();
}
}
// close the respective drop http connection
IF (httpClient = null!) {
the try {
httpClient.close ();
} the catch (IOException E) {
e.printStackTrace ();
}
}
}
}

// public static void main(String[] args) {
// String url ="http://114.67.96.32:8086";
//
//
// System.out.println("success"+doGet(url));
// }

@Test
public void shutdown() {
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
InputStream is = null;
String url = "http://你的路径/api/v1/ManualRecordStop?token=???&session=?????????";


//封装请求参数
List<NameValuePair> params = Lists.newArrayList();
params.add(new BasicNameValuePair("cityEname", "henan"));
STR = String "";
the try {
convert key-value pair // to
STR = EntityUtils.toString (new new UrlEncodedFormEntity (the params, Consts.UTF_8));
System.out.println; ( "STR" + STR)
// Get request to create
= new new HttpGet HttpGet HttpGet (URL + + STR "?");
// get request execution,
response = httpClient.execute (HttpGet);
// get a response form
the HttpEntity = response.getEntity Entity ();
! IF (Entity = null ) {
iS = entity.getContent ();
// input stream of bytes is converted to
the BufferedReader the BufferedReader br = new new (new new the InputStreamReader (iS, Consts.UTF_8));
String body = null;
the while ((= br.readLine body ()) = null!) {
System.out.println (body);
}

}
} the catch (a ParseException E) {
e.printStackTrace ();
} the catch (IOException E) {
e.printStackTrace ();
} the finally {
// Close the input stream, the release of resources
IF (IS = null!) {
the try {
is.close ();
} the catch (IOException E) {
e.printStackTrace ();
}
}
// consume substantial contents
IF (Response! = null) {
the try {
response.close ();
} the catch (IOException E) {
e.printStackTrace ();
}
}
// close the respective drop http connection
IF (httpClient = null!) {
the try {
httpClient.close ();
} the catch (IOException E) {
e.printStackTrace ();
}
}
}
}
}

Guess you like

Origin www.cnblogs.com/jokerLiuloss/p/12175408.html