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.

5
  • 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
    Commented Nov 15, 2016 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
    Commented Nov 15, 2016 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
    Commented Nov 15, 2016 at 18:51
  • you are getting 401 because you are not authorized to your second web application. Commented Nov 16, 2016 at 6:08
  • Do you have permission on the second site collection?
    – Karthik
    Commented Mar 8, 2018 at 17:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.