SiteCore 项目 WebAPI 远程调用失败,返回 403

SiteCore Item WebAPI Remote Call failing with 403

大家好我正在尝试远程调用 SiteCore Item Web API Sitecore 未安装且无法从远程计算机调用服务。我从远程计算机收到 403,但从 Sitecore 机器收到响应 200。

下面是示例代码片段

   namespace SiteCoreApi
  {
class Program
{
    static void Main(string[] args)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create          ("http://dpc/sitecore/api/ssc/item/?path=/sitecore/content/home");

        request.Headers["X-Scitemwebapi-Username"] = @"sitecore\admin";
        request.Headers["X-Scitemwebapi-Password"] = "b";

        try
        {
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Console.Write(String.Format("Content length is {0}", response.ContentLength));
            Console.Write(String.Format("Content type is {0}", response.ContentType));
            // Get the stream associated with the response.
            Stream receiveStream = response.GetResponseStream();
            // Pipes the stream to a higher level stream reader with the required encoding format. 
            StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
            Console.Write("<br /> Response stream received. <br />");
            Console.Write(readStream.ReadToEnd());
            Console.ReadLine();

        }

        catch(Exception ex)
        {
            Console.Write(ex.Message);
        }

    }
}

}

我认为发生这种情况是因为 sitecore 服务安全策略默认设置为 ServicesLocalOnlyPolicy,您需要将其更改为 ServicesOnPolicy 您可以在以下位置找到这些配置: App_Config/include/Sitecore.Services.client.config,但要小心更改此文件中的设置可能会影响 Sitecore 安装的安全性