3

We are currently working on a site that has a publicly available version already out on the internet, the client needed to move over to our in house hosting environment which is SharePoint 2013 publishing based. so for example you can publicly go to www.somesite.org and get the current live site, our site which is using the same domain name is only available to us internally with our hosts files pointing to it. We also have a dev version of the site set up at devsomesite.org.

Now with that background out of the way here is the issue. On the current dev version of the site I have no issue posting to the rest api, however on the version of the site that we use the hosts file to access I can do GETS against list items but if I try and POST I get a 200 Ok response but the post never occurs.

Has anyone run across this issue? Is it because we are pointing to the site via Hosts and the site is not available via DNS?

For example the below code works, I get a return with status 200, but nothing is posted and it returns ALL the list contents and not the item that it should have created.

var item = {
  Title : 'Some Title',
  category : 'some category',
  job : 'some job',
  section : 'some section',
  metadata : { 
      type : 'SP.Data.Userjobs2ListItem',
  }
}
function PostListItem(){
  console.log('Posting List Items');
  let siteUrl = _spPageContextInfo.webAbsoluteUrl;
  console.log(siteUrl);
  let requestUrl = siteUrl + 
'/_api/web/lists/GetByTitle(\'userjobs2\')/items/';
  $.ajax({
    url: requestUrl,
    headers : {            
        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
        "Accept": "application/json; odata=verbose",
        "content-type": "application/json; odata=verbose"
    },
    type:'POST',
    data: item,
    success : function(data){
      var res = (data);
      console.log(res);
    },
    error : function(data){
       console.log(data);
    }
  });
}
PostListItem();
0

So the answer to my question is 2 fold.. I could not successfully post to the REST api because I had a rule in my web.config which was converting all requests to lowercase because of SEO. This was causing errors in the REST API. I could successfully perform GETS but not posts. Removing this rule fixed the problem and I could POST once again.

The second problem was a result of the Windows Server LoopbackCheck and was preventing me from logging into my own site from the server itself. See this article for the fix: https://blogs.technet.microsoft.com/sharepoint_foxhole/2010/06/21/disableloopbackcheck-lets-do-it-the-right-way/

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.