[HttpClient]: How to find the final URI after redirects
来源:互联网 发布:copy软件 编辑:程序博客网 时间:2024/05/05 04:11
1. Use a local HttpContext
To get final request location: -------- HttpClient httpClient = new DefaultHttpClient(); HttpGet httpget = new HttpGet("https://localhost/"); HttpContext context = new BasicHttpContext(); HttpResponse response = httpClient.execute(httpget, context); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } HttpUriRequest request = (HttpUriRequest) context.getAttribute( ExecutionContext.HTTP_REQUEST); System.out.println(request.getURI());
2. User a custom RedirectStrategy
To get all intermediate redirect locations: -------- DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.setRedirectStrategy(new DefaultRedirectStrategy() { @Override public URI getLocationURI(HttpResponse response, HttpContext context) throws ProtocolException { URI uri = super.getLocationURI(response, context); System.out.println("redirect - > " + uri); return uri; } }); HttpGet httpget = new HttpGet("https://localhost/"); HttpResponse response = httpClient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); }
Reference:
http://old.nabble.com/Finding-out-the-URL-after-a-redirect-td20433446.html
http://old.nabble.com/POST-response-with-status-302-doesn't-redirect-td30134484.html
- [HttpClient]: How to find the final URI after redirects
- how to find the badi?
- How to Find the Prefect Color?
- How to find the ABAP examples
- How to do the trade after new updates?
- How to recover after rebooting the LFS procession
- How to handle the session in HttpClient 4.1
- How to find the source code of the special command?
- How to Find the Best Person for the Job
- How To Change The Asm Rebalancing Power After Starting The Rebalancing Process
- How to find the file which contain a specified string
- How-To Find the Source of "Unaligned Access"
- NFL Playoffs 2011: How to Find the Perfect NFL Cheerleader
- How to find the HTML5 feature for your HTML5R
- Selenium - How to find the element in iframe
- How to Find the Standard Deviation in Minitab
- How to find the lost testpoint in weblogic12?
- How to find the crash point: Android Native crash
- 工作积累之折线等分算法
- 自定义标签
- C/C++易错点56条(持续更新中)
- Android Dev Guide—— Application Fundamentals(中文版)
- 编译静态库和动态库的Makefile文件
- [HttpClient]: How to find the final URI after redirects
- 绿色装修不是空概念
- htmlcomplete#CompleteTags 报错, classlines未找到
- jquery trim() 功能源代码
- rapidxml 使用手册1
- Key-Value Observing 快速入门
- Android TabHost
- RS232 RS485 RS422 串口
- 雷军的清华演讲-掌握你的运气