Try our conversational search powered by Generative AI!

Content Delivery API - Wrapper function for making REST Content API Calls


Hello All,

We are trying to implement the token validation using JWT Security Token and we were able to successfully generate the token.

Based on the token validation we are trying to retrieve the Content API Results, but the issue we are facing is as follows:

We found that "ContentResultService" is the wrapper function where we were able to fetch the request url and other data 's from the request URL.

But while trying to get the HttpWebResponse  from the request URL, it is looped (it hits the start of BuildContent() ) and we are unable to get the response.

    public class CustomContentResultService : ContentResultService
        public CustomContentResultService(IContentApiSerializer contentApiSerializer) : base(contentApiSerializer)
        public override StringContent BuildContent(object value)
            string token = "some_token";
            bool hasValue = PageHelper.TokenValidation(token);
            if (hasValue)
                var requestURL = HttpContext.Current.Request.Url.ToString();
                string response = string.Empty;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestURL);
                request.Method = "GET";
                request.ContentType = "application/json";
                request.Headers.Add("Accept-Language", "en");
                request.Headers.Add("Authorization", "Bearer " + token);
                HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();


Kindly provide your suggestions to resolve this issue.


Jan 14, 2021 12:54

Can you try to pass any other requestURL instead of the current request URL and then check the behaviour?

Jan 15, 2021 4:55

Issue #1: Tried passing other request URL's as well, but the looping is happening...

Issue #2: BuildContent() Method's parameter (object value) always provides the Error response code as "Unauthorized"

Also,Could you please confirm whether  "ContentResultService" is the wrapper function where we used to perform HTTPWebRequest and HTTPWebResponse, if not kindly provide us the right wrapper function where we could make use of these content REST API Calls?

Jan 15, 2021 7:12


ContentResultService is responsible for serializing the content and put it in a StringContent object before it's served in the web API. It's still a bit unclear what you're acutally trying to achieve here.

What is the goal? To protect the Content Delivery API with OpenID Connect and use Okta for authenticating users, then the users should be able to call the Content Delivery API with the access token they received when logging in through Okta?

Jan 20, 2021 16:45


Here we have resolved our issue by,

Implementing "CustomContentAPIAuthorizationService" which inherits "ContentAPIAuthorizationService". Then need to add the created CustomContentAPIAuthorizationService in DependencyResolverInitialization.cs. With this, we resolved our Issue #1: Looping issue.

Please refer the below links for more details:

Let us know if there is any other best approaches.



Jan 27, 2021 8:50
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.