Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • 4.0.1, 4.1 Alpha2
    • None
    • None
    • None
    • Win7, Netbeans 6.8, JDK6_20

    Description

      i have a server which gives me a authentication string in the response header. with that i can connect to my streamserver and download a video file eg. mp3/avi...

      my server sends:
      [X-Powered-By=PHP/5.2.11,
      Cache-Control=no-cache, no-store, must-revalidate,
      Pragma=no-cache,
      Expires=Sat, 26 Jul 2010 05:00:00 GMT,
      Content-Type=audio/mpeg,
      Location=http://mysub.myhost.com/3728/20713728.avi?__dd1__=1274891260,
      Content-Length=0,
      Connection=close,
      Date=Wed, 26 May 2010 16:17:40 GMT,
      Server=lighttpd/1.5.0]

      this is the 302 (says wireshark) but HttpClient will just not follow
      but it must because the headers etc. are used for authentication
      how can i achieve that?

      Attachments

        Activity

          Generate a complete wire / context log of the HTTP session as described here [1] and attach it to the report.

          Oleg

          [1] http://hc.apache.org/httpcomponents-client-4.0.1/logging.html

          olegk Oleg Kalnichevski added a comment - Generate a complete wire / context log of the HTTP session as described here [1] and attach it to the report. Oleg [1] http://hc.apache.org/httpcomponents-client-4.0.1/logging.html

          Per section 10.3.3 of RFC 2616 responses 302 (FOUND) to any method other than GET or HEAD may not be redirected automatically. Your method is POST.

          If you want to override this standard compliant behaviour you can provide a custom RedirectHandler in version 4.0.x or a custom RedirectStrategy in version 4.1

          Oleg

          olegk Oleg Kalnichevski added a comment - Per section 10.3.3 of RFC 2616 responses 302 (FOUND) to any method other than GET or HEAD may not be redirected automatically. Your method is POST. If you want to override this standard compliant behaviour you can provide a custom RedirectHandler in version 4.0.x or a custom RedirectStrategy in version 4.1 Oleg
          olze84 oliver z added a comment - - edited

          well thats sad.. because i dont know any browser which does not work (FF, IE, Opera, ..)
          then i have to do this myself

          thats the code that works for me - if someone has an equal problem

          1. HttpClient client = new HttpClient();
          2. client.setRedirectStrategy(new DefaultRedirectStrategy() {
          3. @Override
          4. public boolean isRedirected(HttpRequest hr, HttpResponse hr1, HttpContext hc) {
          5. if (hr1.getStatusLine().getStatusCode() == 302) { # return true; # }
          6. return false;
          7. }
          8. @Override
          9. public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) {
          10. HttpGet get = null;
          11. try { # # String newLocation = "" + response.getFirstHeader("Location"); # newLocation = newLocation.substring(newLocation.indexOf("Location:")+10); # get = new HttpGet(newLocation); # # # }

            catch (Exception ex)

            { # System.out.println(ex.getLocalizedMessage()); # }
          12. return get;
          13. }
          14. });
          olze84 oliver z added a comment - - edited well thats sad.. because i dont know any browser which does not work (FF, IE, Opera, ..) then i have to do this myself thats the code that works for me - if someone has an equal problem HttpClient client = new HttpClient(); client.setRedirectStrategy(new DefaultRedirectStrategy() { @Override public boolean isRedirected(HttpRequest hr, HttpResponse hr1, HttpContext hc) { if (hr1.getStatusLine().getStatusCode() == 302) { # return true; # } return false; } @Override public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) { HttpGet get = null; try { # # String newLocation = "" + response.getFirstHeader("Location"); # newLocation = newLocation.substring(newLocation.indexOf("Location:")+10); # get = new HttpGet(newLocation); # # # } catch (Exception ex) { # System.out.println(ex.getLocalizedMessage()); # } return get; } });

          > i dont know any browser which does not work (FF, IE, Opera, ..)

          HttpClient is not a browser.

          > # newLocation = newLocation.substring(newLocation.indexOf("Location:")+10);

          This does not seem right.

          Why do need to override #getRedirect at all? Anyway, you should be using #getLocationURI method to extract redirect location.

          Oleg

          olegk Oleg Kalnichevski added a comment - > i dont know any browser which does not work (FF, IE, Opera, ..) HttpClient is not a browser. > # newLocation = newLocation.substring(newLocation.indexOf("Location:")+10); This does not seem right. Why do need to override #getRedirect at all? Anyway, you should be using #getLocationURI method to extract redirect location. Oleg
          olze84 oliver z added a comment -

          thanks for your replay
          i changed the code as you mentioned and it works - thx (i was sure there is such a method but i didnt find it and time pressure forces me to continue with other parts of the project))

          i have overwritten the isRedirect because i thought thats what is beeing checked (if its POST and 302 -> return false and dont follow)

          > HttpClient is not a browser.
          you are right, but it would be nice if there would be such a option like setCompatibility(Mode.FIREFOX3)

          olze84 oliver z added a comment - thanks for your replay i changed the code as you mentioned and it works - thx (i was sure there is such a method but i didnt find it and time pressure forces me to continue with other parts of the project)) i have overwritten the isRedirect because i thought thats what is beeing checked (if its POST and 302 -> return false and dont follow) > HttpClient is not a browser. you are right, but it would be nice if there would be such a option like setCompatibility(Mode.FIREFOX3)

          People

            Unassigned Unassigned
            olze84 oliver z
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: