Series<Parameter> params = ctx.getParameters();
params.add("followRedirects", "true");
ctx.setParameters(params);
How to get restlet to follow 301 redirects
-
05-10-2022 - |
質問
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
解決
他のヒント
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.
所属していません StackOverflow