2

I'm trying to create an item using ItemService in Sitecore.Services.Client.

Item creation is working fine and response looks like this:

201 (Created).

Location: /item/0727f965-2338-43cc-bd88-5071ad3f7a12?database=master

My need is to get this location in the response header.

During that I'm facing this issue:

refused to get unsafe header "Location" Error

Below is attached my code sample:

 request.setRequestHeader('Access-Control-Expose-Headers', 'Location');
            request.onreadystatechange = function () {
                if (this.readyState == 4) {
                    console.log(this.status); 
                    console.log(this.getResponseHeader('Location'));                                       
                }
            };
  • Have you tried request.getResponseHeader('Location')? or request.getAllResponseHeaders();? – Marek Musielak Feb 6 '19 at 7:37
  • 1
    both i tried. for request.getAllResponseHeaders(); - i get only simple request headers like cache control,expires etc for request.getResponseHeader('Location') -i'm getting error – Rajasekar Feb 6 '19 at 7:39
  • It looks like this may be caused by Cross Domain Resource Sharing limitations stackoverflow.com/a/5837798/157833 – Marek Musielak Feb 6 '19 at 7:45
  • 1
    if this so, where i pass this web.config ? or sitecore.services.client.config? – Rajasekar Feb 6 '19 at 7:46
2

I solved it by using the below code in web.config

   <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Expose-Headers" value="*"/>
        <remove name="X-Powered-By" />
      </customHeaders>
    </httpProtocol>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.