curl --get --include 'https://open.canpoint.net/openapi/manfenbase/get_video?video_id=视频ID' -H 'appid:您自己的appid \n appkey:您自己的appkey'
String httpUrl = "https://open.canpoint.net/openapi/manfenbase/get_video";
String httpArg = "?video_id=视频ID';
String jsonResult = request(httpUrl, httpArg);
System.out.println(jsonResult);
/**
* @param urlAll
* :请求接口
* @param httpArg
* :参数
* @return 返回结果
*/
public static String request(String httpUrl, String httpArg) {
BufferedReader reader = null;
String result = null;
StringBuffer sbf = new StringBuffer();
httpUrl = httpUrl + "?" + httpArg;
try {
URL url = new URL(httpUrl);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setRequestMethod("GET");
// 填入apikey到HTTP header
connection.setRequestProperty("appid", "您自己的appid");
connection.setRequestProperty("appkey", "您自己的appkey");
connection.connect();
InputStream is = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String strRead = null;
while ((strRead = reader.readLine()) != null) {
sbf.append(strRead);
sbf.append("rn");
}
reader.close();
result = sbf.toString();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
string url = "https://open.canpoint.net/openapi/manfenbase/get_video";
string param = "?video_id=视频ID';
string result = request(url,param);
///
/// 发送HTTP请求
///
///
请求的URL
///
请求的参数
///
请求结果
public static string request(string url, string param)
{
string strURL = url + '?' + param;
System.Net.HttpWebRequest request;
request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
request.Method = "GET";
// 添加header
request.Headers.Add("appid", "您自己的appid");
request.Headers.Add("appkey", "您自己的appkey");
System.Net.HttpWebResponse response;
response = (System.Net.HttpWebResponse)request.GetResponse();
System.IO.Stream s;
s = response.GetResponseStream();
string StrDate = "";
string strValue = "";
StreamReader Reader = new StreamReader(s, Encoding.UTF8);
while ((StrDate = Reader.ReadLine()) != null)
{
strValue += StrDate + "rn";
}
return strValue;
}