2010-09-08 3 views
0

Je trouve une URL qui httpclient ne semble pas être la manipulation redirections vers:HttpClient incapable de 302 ce lien?

http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGrJk-F7Dmshmtze2yhifxRsv8sRg&url=http://www.mtv.com/news/articles/1647243/20100907/story.jhtml

doit 302: http://www.mtv.com/news/articles/1647243/20100907/story.jhtml

quand je regarde les en-têtes dans le navigateur tout semble bon:

HTTP/1.1 302 Moved Temporarily 
Content-Type: text/html; charset=UTF-8 
Location: http://www.mtv.com/news/articles/1647243/20100907/story.jhtml 
Content-Length: 258 
Date: Wed, 08 Sep 2010 18:40:21 GMT 
Expires: Wed, 08 Sep 2010 18:40:21 GMT 
Cache-Control: private, max-age=0 
X-Content-Type-Options: nosniff 
X-Frame-Options: SAMEORIGIN 
X-Xss-Protection: 1; mode=block 
Server: GSE 
Set-Cookie: PREF=ID=024209255b405b06:TM=1283971221:LM=1283971221:S=AG-13_7Cjg_EqlRY; expires=Fri, 07-Sep-2012 18:40:21 GMT; path=/; domain=.google.com 
Connection: close 

Cependant httpclient ne semble pas me donner l'URL finale. Voici le code que j'utilisais

HttpHead httpget = null; 
HttpHost target = null; 
HttpUriRequest req = null; 

String startURL = "http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGrJk-F7Dmshmtze2yhifxRsv8sRg&url=http://www.mtv.com/news/articles/1647243/20100907/story.jhtml"; 
HttpContext localContext = new BasicHttpContext(); 
localContext.setAttribute(ClientContext.COOKIE_STORE,HttpClientFetcher.emptyCookieStore); 
httpget = new HttpHead(startURL); 

HttpResponse response = httpClient.execute(httpget, localContext); 

Header[] test = response.getAllHeaders(); 
for(Header h: test) { 
logger.info(h.getName()+ ": "+h.getValue()); 
} 

target = (HttpHost) localContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST); 

req = (HttpUriRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST); 

// STILL PRINTS OUT THE GOOGLE NEWS LINK 
finalURL = target+""+req.getURI(); 

Est-ce que je fais quelque chose de mal? grâce

+0

Comment bien que 'à 302' ait été un verbe!?! –

Répondre

0

trouvé la réponse dans la liste de diffusion httpclient ...

Google ne traite pas une tête et obtenir le même, de sorte que l'EEG réoriente avec 302 et la demande HEAD donne 200 OK