質問

I am currently trying to get a resource which could be behind possible more than one redirect. My code looks like this:

        Client client = new Client(new Context(), Protocol.HTTP);
        Context ctx = client.getContext();
        ctx.getParameters().add("followRedirects", "true");      
        ClientResource cr = new ClientResource(ctx,u); 
        Representation r = cr.get();

However redirects are not followed. What am I doing wrong?

This is Restlet 2.1 on Google App Engine

役に立ちましたか?

解決

Series<Parameter> params = ctx.getParameters();
params.add("followRedirects", "true");
ctx.setParameters(params);

他のヒント

You can set this also using the ClientResource class:

clientResource.setFollowingRedirects(true);

In my case (using Restlet 2.3.9) this seems to be the default behavior.

This method could be also useful in your case:

setMaxRedirects(int maxRedirects) 

sets the maximum number of redirections that can be automatically followed for a single call.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top