Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to add header keys to URL to see result of action i connect to it
 add Keys Headers :

content type :application/json

Authorization : eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJBZG1pbiIsInVzZXIiOnsiaWQiOiJBZG1pbiJ9fQ.-sfTpg64pHfsXPDvS_vFQHn0LqogPXRDIYg0zzaZHik


the code below give me actually result as i need on postman but

on browser not give me result because URL not have header keys

so that how to add header keys to URL to see result on browser ?

What I have tried:

public async Task InvokeAsync(HttpContext context)
        {
            var request = await FormatRequest(context.Request);
            var CheckExistAccessToken = context.Request.Headers.ContainsKey("Authorization");
            if (CheckExistAccessToken == true)
            {
                var AccessTokenValue = context.Request.Headers["Authorization"].SingleOrDefault();
                bool isvalid = _tockenvalidator.ValidateToken(AccessTokenValue);
                if (!isvalid)
                {
                    context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                    await context.Response.WriteAsync("invalid Token");
                }
               
                else
                {
                    
                    var requestes = await FormatRequest(context.Request);
                    var originalBodyStream = context.Response.Body;

                    //Create a new memory stream...
                    using (var responseBody = new MemoryStream())
                    {
                        
                        context.Response.Body = responseBody;

                       
                        await _next(context);

                        
                        var response = await FormatResponse(context.Response);

                       
                        await responseBody.CopyToAsync(originalBodyStream);
                    }
                    
                }
            }
            else
            {
                var requestes = await FormatRequest(context.Request);
             
                var originalBodyStream = context.Response.Body;

              
                using (var responseBody = new MemoryStream())
                {
                   
                    context.Response.Body = responseBody;

       
                    await _next(context);

                   
                    var response = await FormatResponse(context.Response);

                    
                    await responseBody.CopyToAsync(originalBodyStream);
                }
            }
        }
Posted
Comments
F-ES Sitecore 30-Sep-19 4:11am    
Browsers don't typically let you set custom headers, if you want to test this in a browser you'll probably need to use a browser plug-in that lets you set the headers.
ahmed_sa 1-Oct-19 0:21am    
thank you for reply please how that done I need only understand if cannot be add header from browser how website work it actually will see result from browser when he open it
can you give me more details if possible

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900