3

I want to make a rest call to get web properties (i.e. /_api/web), for a different web application than the current. I have added the response headers

Access-Control-Allow-Credentials : true
Access-Control-Allow-Origin : *
Access-Control-Request-Method : GET,POST,HEAD,OPTIONS

in IIS.

Then I tried to make a ajax call

    $.support.cors = true;
    $.ajax({
        url: "http://othersite/_api/web",
        type: "GET",
        //timeout: 8000,
        //contentType: "application/json;odata=nometadata",
        //cache: false,
        crossDomain:true,
        headers: {
            "Accept": "application/json;odata=verbose"
        },
        xhrFields: { withCredentials: true },
        success: function(data) {
            console.log('worked');
        },
        error: function(jqXHR, textStatus, errorThrown) {
            console.log('error');
        }
    });

but it doesn't work. I get 401 unauthorized. Does anyone know what is wrong?

Thanks

I even tried this

http://www.thesharepointguide.com/create-a-list-item-in-another-site-collection/

but same problem.

  • I'm facing the same problem and the last answer was: You can't. So I create a web service and I connect to the other site with CSOM with credentials. – Marco Nov 15 '16 at 17:59
  • Are the two site collections in different domains? I've used REST across site collections with no issues, but they're in the same domain. – wjervis Nov 15 '16 at 18:48
  • Its actually in different web applications, so one site is mysite and the other is mysite:9000. I believe this is considered different domain. – omega Nov 15 '16 at 18:51
  • you are getting 401 because you are not authorized to your second web application. – Sergei Sergeev Nov 16 '16 at 6:08
  • Do you have permission on the second site collection? – Karthik Mar 8 '18 at 17:28

Your Answer

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

Browse other questions tagged or ask your own question.