标签:mp3 except referer cdb import package request windows character
package xcy;
import java.io.IOException;
import java.net.URLEncoder;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
@WebServlet("/list")
public class Xcy extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 1 ? ??
req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
resp.setContentType("text/html;charset=UTF-8");
// 2 ?
String key = req.getParameter("key"); // ctrl + shift + L ?
key = URLEncoder.encode(key,"UTF-8"); // %A8%A5%AA
// 3 ?
// 4 ?
// 5 ?
// ? ? ? ???
// java ? ??? : httpClient
// 1> HttpClient
HttpClient httpClient = new HttpClient();
// 2> ? ? GetMethod PostMethod
String url = "http://kuwo.cn/api/www/search/searchMusicBykeyWord?key="+key+"&pn=1&rn=30&httpsStatus=1&reqId=5087bc20-3f92-11eb-8461-5f085ce62d18";
GetMethod getMethod = new GetMethod(url);
// 3>? getMehtod ? ?
getMethod.setRequestHeader("Cookie", "Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1608118293; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1608118293; _ga=GA1.2.1648469662.1608118293; _gid=GA1.2.408464032.1608118293; _gat=1; kw_token=8JLSPB6J1ET");
getMethod.setRequestHeader("csrf", "8JLSPB6J1ET");
getMethod.setRequestHeader("Referer", "http://kuwo.cn/search/list?key=%E5%91%A8%E6%9D%B0%E4%BC%A6");
getMethod.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36");
// 4>? httpClient ? getMethod
int sta = httpClient.executeMethod(getMethod);
// if(sta !=HttpStatus.SC_OK) {
// System.out.println("您的链接失效,请重新测试");
// }
// 5>? getMethod ? ? ?
byte[] body = getMethod.getResponseBody();
String data = new String(body);
// ? : ? ?
// ? : ? ? ? ? ? ?
// 6, ? ?
resp.getWriter().write(data);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
11
11
11
11
11
11
11
11
11
package xcy;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
@WebServlet("/musiconeservlet")
public class XcyOne extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//1,设置编码方式
req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
resp.setContentType("text/html;charset=UTF-8");
//2,处理请求信息
String rid = req.getParameter("rid");
//3,使用httpclient链接酷我音乐
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod("https://kuwo.cn/url?format=mp3&rid="+rid+"&response=url&type=convert_url3&br=128kmp3&from=web&t=1608168223781&httpsStatus=1&reqId=80ae4c61-4006-11eb-b4b1-b5e210c11b6b");
int sta = httpClient.executeMethod(getMethod);
if(sta !=HttpStatus.SC_OK) {
System.out.println("服务器出错,请重新检验");
}
byte[] body = getMethod.getResponseBody();
String data = new String(body);
//4,给出相应信息
resp.getWriter().write(data);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
标签:mp3 except referer cdb import package request windows character
原文地址:https://www.cnblogs.com/hedejia/p/14157684.html