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

时间:2016-11-15 18:58:43

标签: sitecore sitecore8

大家好我想尝试远程调用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);
        }

    }
}

}

1 个答案:

答案 0 :(得分:3)

我认为这是因为sitecore服务安全策略默认设置为a:12:{i:1;s:2:"15";i:2;s:2:"10";i:3;s:2:"30";i:4;s:2:"50";i:5;s:3:"120";i:6;s:3:"240";i:7;s:3:"480";i:8;s:3:"960";i:9;s:4:"3786";s:1:"A";s:3:"100";s:1:"C";s:2:"60";s:1:"B";s:5:"18930";} ,您需要将其更改为ServicesLocalOnlyPolicy,您可以在以下位置找到这些配置: App_Config / include / Sitecore.Services.client.config,但要小心更改此文件中的设置可能会影响Sitecore安装的安全性