工作小总结

java获取 Response 中的 location属性-【抖音-douyin】

需求:如图:得到页面上的location的值代码实现ps:参考:https://www.cnblogs.com/zhougaojun/p/4547160.htmlhttps://www.cnblogs.com/niss/p/3711901.htmlJsoup的实现public String json() throws IOException {&n

需求:

6e032d38e12d8610e7391ce9989bea74.png

如图:得到 页面上的 location 的值


代码实现

插播一条


下面这个公众号是凯哥开发的,福利号:外卖、买菜、电商领Q的

67db93da54df097b6017fa8666079592.png

怎么领券?

f02b1847f3c94a44c2d6f0bca121443d.png


ps:参考: https://www.cnblogs.com/zhougaojun/p/4547160.html

https://www.cnblogs.com/niss/p/3711901.html

Jsoup 的实现

	public String json() throws IOException {
		
		 Response execute = Jsoup.connect("https://www.freepik.com/download-file/1088379")
				.followRedirects(false)
				.method(Method.GET)
				.execute();
		
		return execute.headers("location").get(0);
	}



旧版httpclient

private String getMaxUrl(String img_downloard_url) {
		String locale ="";
		//创建Httpclient对象
		CloseableHttpClient httpClient = HttpClients.createDefault();
		

		HttpParams params = httpClient.getParams();  
		params.setParameter(ClientPNames.HANDLE_REDIRECTS, false);
		

		//创建httpGet对象,设置url地址:
		HttpGet httpGet = new HttpGet(img_downloard_url);
		CloseableHttpResponse response= null;
		try {
			
			//使用httpClient发起请求 获取 response
			response = httpClient.execute(httpG

原创不易,完成人机校验,阅读全文

相关推荐