Return-Path: X-Original-To: apmail-hc-httpclient-users-archive@www.apache.org Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 82C22FE44 for ; Tue, 7 May 2013 15:11:23 +0000 (UTC) Received: (qmail 60757 invoked by uid 500); 7 May 2013 15:11:23 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 60662 invoked by uid 500); 7 May 2013 15:11:22 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 60643 invoked by uid 99); 7 May 2013 15:11:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 May 2013 15:11:21 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_FRT_BELOW2 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of stephen.butler@gmail.com designates 209.85.214.179 as permitted sender) Received: from [209.85.214.179] (HELO mail-ob0-f179.google.com) (209.85.214.179) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 May 2013 15:11:17 +0000 Received: by mail-ob0-f179.google.com with SMTP id xn12so635470obc.10 for ; Tue, 07 May 2013 08:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=ONV40k2VGR7qVSUuAZ6b4LnpXmQdYCBr6RDwxpMb0Os=; b=xc1Sv+PvhvIHY/Q9xx3OeRsZ5x0Bbz4JG0LjtIJTXW5AT7KKuFrR68u1yelgzT7bYO 0aApisk6UnmXCHAdDNS1bslj7B2euVlxTNvi4Xlm+KttG2K8VZUDZlmKzVTLuYiXrTq6 rEWAs2yqYPO9RwmnXOsGmuuX3YXtVlAU1M3j9+7i0Wl8R7Cj02h6WN+fRJLYJ6NXTB5S 5xdHFz2+ayZR8SJFJDfTnzDdy8Q64dle2zhjZQCXhgv5AmyJIPoBa0yiCdb+6Sedy8QJ Ctv/O24IawcBBv9TF1Ec6mTKk6FtzAUF4gyPLDAZ//P/vVJFPKooUrHkHx95jLUuKQo3 qgag== MIME-Version: 1.0 X-Received: by 10.60.58.99 with SMTP id p3mr683704oeq.23.1367939456563; Tue, 07 May 2013 08:10:56 -0700 (PDT) Received: by 10.182.27.102 with HTTP; Tue, 7 May 2013 08:10:56 -0700 (PDT) In-Reply-To: References: Date: Tue, 7 May 2013 10:10:56 -0500 Message-ID: Subject: Re: why are so different the response headers as reported by wget and httpclient? From: "Stephen J. Butler" To: HttpClient User Discussion Content-Type: multipart/alternative; boundary=089e013d0758624b5704dc2239ac X-Virus-Checked: Checked by ClamAV on apache.org --089e013d0758624b5704dc2239ac Content-Type: text/plain; charset=ISO-8859-1 On Tue, May 7, 2013 at 3:36 AM, Albretch Mueller wrote: > > It's passing the wrong 'Host' line. That's why you are getting a 404. > > well, the code section in which I set the host I pasted bellow ( > notice how I set the Host as part of the Request Headers {"Host", > (httpGet.getURI()).getHost()} ): Yes, but that's not correct after the redirect. First time it connects the 'Host' line should be 'download.ted.com'. But the second time, after following the redirect, it needs to be 'video.ted.com'. > > Are you using standard code to handle the redirect, or writing your own? > > I will have to do the redirect myself and I would like to handle/get > all the response headers of every redirect. How do you do that? Could > you point me to some basic redirect code example? > > ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ > HttpGet httpGet = new HttpGet(aGetURL); > String aRqLn = httpGet.getRequestLine().toString(); // Request Line > System.err.println("// __ httpGet.getRequestLine(): |" + aRqLn + "|"); > > ... > // __ parsing host from URL > String aHost = (httpGet.getURI()).getHost(); > System.err.println("// __ aHost: |" + aHost + "|"); > > String[][] aRqHdrs = new String[][]{ > {"Host", aHost} > , {"Connection", "keep-alive"} > , {"User-Agent", "Mozilla/5.0 (X11; Linux i686; rv:10.0.4) > Gecko/20100101 Firefox/10.0.4 Iceweasel/10.0.4"} > , {"Accept", "text/html, text/*;q=0.9, image/jpeg;q=0.9, > image/png;q=0.9, image/*;q=0.9, */*;q=0.8"} > , {"Accept-Encoding", "gzip, deflate, x-gzip, x-deflate"} > , {"Accept-Charset", "utf-8,*;q=0.5"} > , {"Accept-Language", "en-US,en;q=0.9"} > }; > I see, you're setting the request header manually! That's why HttpClient is failing to properly set the Host header. I'd suggest you not set the Host header manually and let HttpClient do it. It will add it itself; that's mandated by the HTTP 1.1 spec. If you insist on handling the redirect manually, set the ClientPNames.HANDLE_REDIRECTS parameter to Boolean.FALSE. Then the return from executing your request will be the raw redirect, and you'll have to catch that case and resubmit the request on the proper URL. --089e013d0758624b5704dc2239ac--