×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    1

    Question Http - Redirect Issue

    Does any one have experience on resolving the new Location for redirection responses from a HTTP server?

    Description of the issue:
    1) Do HTTP request with method POST to known URL.
    2) > Server response: Redirect: 301 Moved Permanently
    3) > Callback in MHTTPTransactionCallback::MHFRunL() with THTTPEvent::ERedirectRequiresConfirmation, etc...
    4) > Accessing header field "Location" (HTTP::ELocation & RHTTPSession::GetTable()) in RHTTPHeaders when handling any THTTPEvent does not return any data at all?! Still the transaction object seems to have some new URL set by the platform, which does not really work (produces server response with status 404)

    Thank's in advance for any help!

  2. #2
    Regular Contributor
    Join Date
    Aug 2007
    Posts
    105

    Re: Http - Redirect Issue

    hmm, has someone found a resolution for this? how do i get the uri after a THTTPEvent::ERedirectRequiresConfirmation event occured?

  3. #3
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Http - Redirect Issue

    Use HTTP::ELocation.

    I suspect the original posted did not correctly read the header value.

  4. #4
    Regular Contributor
    Join Date
    Aug 2007
    Posts
    105

    Re: Http - Redirect Issue

    Hmm yes, i suspect this is the point where my problem is also

    My Code looks like this:

    case THTTPEvent::ERedirectRequiresConfirmation:
    {
    _LIT(KRedirect, "Redirect");
    iObserver.ClientEvent(KRedirect);
    RStringPool strP = iSession.StringPool();
    RStringF eLoc = strP.StringF(HTTP::ELocation,RHTTPSession::GetTable());
    RHTTPResponse resp = aTransaction.Response();
    RHTTPHeaders hdr = resp.GetHeaderCollection();
    _LIT8 ( KLocStr, "location" );
    RStringF locStr = strP.OpenFStringL ( KLocStr );
    THTTPHdrVal hdrVal;

    // User::LeaveIfError ( hdr.GetField ( eLoc, 0, hdrVal ) );
    // User::LeaveIfError ( hdr.GetParam ( eLoc, locStr, hdrVal ) );
    }

    I tried both of the commented lines, but both return -1, meaning they did not find the field, i guess. Do you know the correct name of the ELocation field?

  5. #5
    Regular Contributor
    Join Date
    Aug 2007
    Posts
    105

    Re: Http - Redirect Issue

    And btw: when i try to resubmit the Transaction using aTransaction.SubmitL(); i get the Error

    KErrHttpCantResetRequestBody -7370 The request body needed to be rewound but the client but it doesn't support

  6. #6
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Http - Redirect Issue

    You are doing this when the transacaction response code is one of 301, 303, 302, 307 -
    (aTransaction.Response().StatusCode()) ?
    IT won't be valid in the other cases

    Here is some example code though its pretty much the same as yours

    RStringF location = p.StringF(HTTP::ELocation,RHTTPSession::GetTable());
    RHTTPHeaders responseHeaders(aTransaction.Response().GetHeaderCollection());

    THTTPHdrVal locationValue;
    User::LeaveIfError(responseHeaders.GetField(location, 0, locationValue));

  7. #7
    Regular Contributor
    Join Date
    Aug 2007
    Posts
    105

    Re: Http - Redirect Issue

    Hi again, thanks a lot Paul for helping!

    It is a 301, i checked with your call. But i still seem to be unable to extract the field. I used your code and it didnt find the field. So i checked the field enumerator and it seems to be empty:

    RHTTPResponse resp = aTransaction.Response();
    RHTTPHeaders hdr = resp.GetHeaderCollection();
    THTTPHdrFieldIter it = hdr.Fields();

    now "if (it.AtEnd())" returns true

  8. #8
    Regular Contributor
    Join Date
    Aug 2007
    Posts
    105

    Re: Http - Redirect Issue

    hmm, anyone got an idea concerning the header fields?

  9. #9
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Http - Redirect Issue

    I would put a packet sniffer like ethereal or wireshard on the emulator box and check the heders are actually being received.

    This sound suspiciously like you are using a non standards compliant http server

  10. #10
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Http - Redirect Issue

    I had a quick look in the S60Webkit and they do it slightly differently

    case THTTPEvent::ERedirectedPermanently:
    case THTTPEvent::ERedirectedTemporarily:
    {
    // for redirects, we must ensure that we properly handle
    // any new or changed uri fragment
    TUriParser8 uriParser;
    uriParser.Parse( aTransaction.Request().URI().UriDes() );
    // check for fragment
    if( uriParser.IsPresent( EUriFragment ) )
    {
    // first extract the portion without fragment to
    // return to Http framework
    TPtrC8 uriNoFrag;
    // extract non-fragment portion into uriNoFrag
    uriParser.UriWithoutFragment( uriNoFrag );
    TUriParser8 parserNoFrag;
    parserNoFrag.Parse( uriNoFrag );
    aTransaction.Request().SetURIL( parserNoFrag );
    // now save the fragment for later use
    const TDesC8& fragment = uriParser.Extract( EUriFragment );
    delete iFragment;
    iFragment = NULL;
    iFragment = HBufC::NewL( fragment.Length() );
    iFragment->Des().Copy( fragment );
    }

    TInt ret = iTransactionObserver->HandleSpecialEventL( *this, aEvent.iStatus );
    //set the redirection flag
    SetIsRedirected(ETrue);
    iUrlRequestInfo->SetRedirectedUrlL( aTransaction.Request().URI().UriDes() );

    //check return value
    if (ret == KErrCancel)
    {
    CancelTransaction( KErrCancel );
    }
    break;
    }

  11. #11
    Registered User
    Join Date
    Mar 2003
    Posts
    23

    Re: Http - Redirect Issue

    I've spent very refreshing saturday evening with very same problem. At least I've some Karhu beer to relieve some pain.

    Anyway. There seems to be a bug in http redirection filter which causes some problems. If you POST data and server responds e.g. 302, the next request the API will do automatically is actually GET (!).

    So workaround for this is to disable the whole filter and implement that redirection logic by yourself.

    Disable:

    Code:
    RHTTPFilterCollection filtColl = iSession.FilterCollection();
    RStringF filterName = iSession.StringPool().StringF(HTTP::ERedirect,RHTTPSession::GetTable());
    filtColl.RemoveFilter( filterName );
    You will get that Location header value in EGotResponseHeader event, so do something like this:

    Code:
    	RStringF location = iSession.StringPool().StringF(HTTP::ELocation,RHTTPSession::GetTable());
    					RHTTPHeaders responseHeaders( aTransaction.Response().GetHeaderCollection() );
    					THTTPHdrVal locationValue;
    					
    					if( responseHeaders.GetField(location, 0, locationValue) == KErrNone )
    					{
    						TBuf8<255> urides( locationValue.StrF().DesC() );
    						
    						TUriParser8 uri;
    						uri.Parse( urides  );
    
    						aTransaction.Cancel();						
    
    						iTransaction.Request().SetURIL( uri );
    						iTransaction.SubmitL();
    					}
    BTW that -7370 error happens because your implementation of MHTTPDataSupplier::Reset() returns something else than KErrNone.

  12. #12
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Http - Redirect Issue

    We can argue whether or not its a bug or by design

    I am posting some comments from the DevKit about this:
    (cite - redirect.cpp)
    // Note: RFC 1945 and RFC 2068 specify that the client is not allowed
    // to change the method on the redirected request. However, most
    // existing user agent implementations treat 302 as if it were a 303
    // response, performing a GET on the Location field-value regardless
    // of the original request method. The status codes 303 and 307 have
    // been added for servers that wish to make unambiguously clear which
    // kind of reaction is expected of the client.

  13. #13
    Registered User
    Join Date
    Oct 2009
    Posts
    4

    Re: Http - Redirect Issue

    Hi ,I also face this problem,how do you solve it ??

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •