function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NisseKnudsenNisseKnudsen 

PageReference.getContent() -> httpclient.RedirectException: Maximum redirects (100) exceeded

Hey Guys!

 

I got a problem where I can't really figure out what I might have done wrong :(

 

First my Code:

PageReference pr = new PageReference( '/servlet/servlet.FileDownload?file=' + filepath );
			Blob internalXmlBlob = pr.getContent();
			String internalXml = internalXmlBlob.toString();
			System.Debug(  internalXml );

 

Now the Debug Log:

 

11:21:20.181 (181269000)|SYSTEM_METHOD_ENTRY|[753]|System.PageReference.getContent()
11:21:22.133 (2133850000)|EXCEPTION_THROWN|[753]|System.VisualforceException: org.apache.commons.httpclient.RedirectException: Maximum redirects (100) exceeded
11:21:22.133 (2133946000)|SYSTEM_METHOD_EXIT|[753]|System.PageReference.getContent()

 

What am I trying to do? I get the Document-File with the Id 'filepath' (parameter) as a blob, convert it to a string and later on try to parse it.

When doing this by using Execute Anonymous in Eclipse IDE I got -no- error.

But in VisualForce, I get this Error shown.

 

Does anyone have a idea?

 

Thanks a lot,

 

Nisse

 

 

 

 

sfdcfoxsfdcfox

Not entirely sure what the problem might be, but I would suggest you just use:

 

 

String internalXml = [select body from document where id = :filePath].body.toString();

There's no reason to use the FileDownload servlet in Apex Code or Visualforce.