Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# HttpWebRequest从SharePoint server获得的响应与其他所有响应不同_C#_Xml_Iis_Sharepoint_Rss - Fatal编程技术网

C# HttpWebRequest从SharePoint server获得的响应与其他所有响应不同

C# HttpWebRequest从SharePoint server获得的响应与其他所有响应不同,c#,xml,iis,sharepoint,rss,C#,Xml,Iis,Sharepoint,Rss,我正在尝试连接到Sharepoint服务器并获取C中的RSS源。这似乎是一个足够简单的任务,但是由于某些原因,当我发送HttpWebRequest时,Sharepoint会向我发送一个不同的响应,以响应我在浏览器中访问该源时得到的响应。具体来说,它返回提要时不带任何s 发出请求的代码如下所示: HttpWebRequest request = WebRequest.Create(URL) as HttpWebRequest; request.Credentials = CredentialCac

我正在尝试连接到Sharepoint服务器并获取C中的RSS源。这似乎是一个足够简单的任务,但是由于某些原因,当我发送HttpWebRequest时,Sharepoint会向我发送一个不同的响应,以响应我在浏览器中访问该源时得到的响应。具体来说,它返回提要时不带任何s

发出请求的代码如下所示:

HttpWebRequest request = WebRequest.Create(URL) as HttpWebRequest;
request.Credentials = CredentialCache.DefaultCredentials; //NTLM

using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) {
    Stream responseStream = response.GetResponseStream();
    // debug: dump the response.
    System.Diagnostics.Debug.WriteLine((new StreamReader(responseStream)).ReadToEnd());
...
在测试这段代码时,我在公共RSS提要上试用了它,效果很好。我启动wireshark查看C发送的请求是否有不同之处,请求和响应如下所示:

GET /Test_Blog_B/_layouts/15/listfeed.aspx?List=%7B5600FFF4-50CD-47C5-BEBC-602874E73748%7D HTTP/1.1
    HTTP/1.1 401 Unauthorized  (text/plain)
GET /Test_Blog_B/_layouts/15/listfeed.aspx?List=%7B5600FFF4-50CD-47C5-BEBC-602874E73748%7D HTTP/1.1 
    HTTP/XML    438 HTTP/1.1 200 OK 
    <?xml version="1.0" encoding="UTF-8"?>
    <!--RSS generated by Microsoft SharePoint Foundation RSS Generator on 12/18/2014 3:50:28 PM -->
    <?xml-stylesheet type="text/xsl" href="/Test_Blog_B/_layouts/15/RssXslt.aspx?List=5600fff4-50cd-47c5-bebc-602874e73748" version="1.0"?>
    <rss version="2.0">
      <channel>
        <title>Blog: Posts</title>
        <link>http://servername/Test_Blog_B/Lists/Posts/AllPosts.aspx</link>
        <description>RSS feed for the Posts list.</description>
        <lastBuildDate>Thu, 18 Dec 2014 15:50:28 GMT</lastBuildDate>
        <generator>Microsoft SharePoint Foundation RSS Generator</generator>
        <ttl>60</ttl>
        <language>en-US</language>
        <image>
          <title>Blog: Posts</title>
          <url>http://servername/Test_Blog_B/_layouts/15/images/siteIcon.png</url>
          <link>http://servername/Test_Blog_B/Lists/Posts/AllPosts.aspx</link>
        </image>
      </channel>
    </rss>
然而,我尝试的其他方法都得到了这个响应cURL输出,为了简洁起见,剪掉了一些标题

* Connected to servername (192.168.170.39) port 80 (#0)
* Server auth using NTLM with user 
> GET /Test_Blog_B/_layouts/15/listfeed.aspx?List=%7B5600FFF4-50CD-47C5-BEBC-602
< HTTP/1.1 401 Unauthorized
* Connection #0 to host servername left intact
* Issue another request to this URL: 'http://servername/Test_Blog_B/_layouts/15/list
feed.aspx?List=%7B5600FFF4-50CD-47C5-BEBC-602874E73748%7D'
* Found bundle for host servername: 0x94eab0
* Re-using existing connection! (#0) with host servername
* Connected to servername (192.168.170.39) port 80 (#0)
* Server auth using NTLM with user ''
> GET /Test_Blog_B/_layouts/15/listfeed.aspx?List=%7B5600FFF4-50CD-47C5-BEBC-602
874E73748%7D HTTP/1.1
< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: text/xml; charset=utf-8
< Last-Modified: Thu, 18 Dec 2014 15:13:06 GMT
< ETag: 1;3;5600fff4-50cd-47c5-bebc-602874e73748;635545156307000000;13319
< Server: Microsoft-IIS/8.5
< X-SharePointHealthScore: 0
< X-AspNet-Version: 4.0.30319
< SPRequestGuid: 7b06d79c-dd72-c064-3da9-961822afeee3
< request-id: 7b06d79c-dd72-c064-3da9-961822afeee3
< X-FRAME-OPTIONS: SAMEORIGIN
< SPRequestDuration: 65
< SPIisLatency: 1
< Persistent-Auth: true
< X-Powered-By: ASP.NET
< MicrosoftSharePointTeamServices: 15.0.0.4569
< X-Content-Type-Options: nosniff
< X-MS-InvokeApp: 1; RequireReadOnly
< Date: Thu, 18 Dec 2014 16:28:44 GMT
< Content-Length: 3061
<
´╗┐<?xml version="1.0" encoding="UTF-8"?>
<!--RSS generated by Microsoft SharePoint Foundation RSS Generator on 12/18/2014
 4:28:44 PM -->
<?xml-stylesheet type="text/xsl" href="/Test_Blog_B/_layouts/15/RssXslt.aspx?Lis
t=5600fff4-50cd-47c5-bebc-602874e73748" version="1.0"?>
<rss version="2.0">
  <channel>
    <title>Blog: Posts</title>
    <link>http://servername/Test_Blog_B/Lists/Posts/AllPosts.aspx</link>
    <description>RSS feed for the Posts list.</description>
    <lastBuildDate>Thu, 18 Dec 2014 16:28:44 GMT</lastBuildDate>
    <generator>Microsoft SharePoint Foundation RSS Generator</generator>
    <ttl>60</ttl>
    <language>en-US</language>
    <image>
      <title>Blog: Posts</title>
      <url>http://servername/Test_Blog_B/_layouts/15/images/siteIcon.png</url>
      <link>http://servername/Test_Blog_B/Lists/Posts/AllPosts.aspx</link>
    </image>
    <item>
      <title>Blog</title>
      <link>http://servername/Test_Blog_B/Lists/Posts/ViewPost.aspx?ID=3</link>
      <description><![CDATA[<div><b>Body:</b> <div class="ExternalClass78B241D68
AE340AF8482D70142AE8DB7"><p>Post</p></div></div>
<div><b>Published:</b> 12/18/2014 3:12 PM</div>
]]></description>
      <author></author>
      <pubDate>Thu, 18 Dec 2014 15:13:06 GMT</pubDate>
      <guid isPermaLink="true">http://servername/Test_Blog_B/Lists/Posts/ViewPost.as
px?ID=3</guid>
    </item>
    <item>
      <title>new post</title>
      <link>http://servername/Test_Blog_B/Lists/Posts/ViewPost.aspx?ID=2</link>
      <description><![CDATA[<div><b>Body:</b> <div class="ExternalClass0BD87B46B
E6F481CA042F2BACC15082C"><p>2ÔÇï</p></div></div>
<div><b>Category:</b> <a onclick="OpenPopUpPage('http://servername/Test_Blog_B/_layo
uts/15/listform.aspx?PageType=4&ListId={7C658DFF-4CEC-4934-98C3-14187E2345CA}&ID
=3&RootFolder=*', RefreshPage); return false;" href="http://servername/Test_Blog_B/_
layouts/15/listform.aspx?PageType=4&ListId={7C658DFF-4CEC-4934-98C3-14187E2345CA
}&ID=3&RootFolder=*">Events</a></div>
<div><b>Published:</b> 12/11/2014 4:55 PM</div>
]]></description>
      <author></author>
      <category>Events</category>
      <pubDate>Thu, 11 Dec 2014 16:55:38 GMT</pubDate>
      <guid isPermaLink="true">http://servername/Test_Blog_B/Lists/Posts/ViewPost.as
px?ID=2</guid>
    </item>
    <item>
      <title>Welcome to my blog!</title>
      <link>http://servername/Test_Blog_B/Lists/Posts/ViewPost.aspx?ID=1</link>
      <description><![CDATA[<div><b>Body:</b> <div class="ExternalClass471F21A09
57043359622B8C8ABB138CF"><p>This is where I'll be sharing my thoughts on topics
that matter to me. Who knows... I might even share pictures, videos and links to
 other interesting stuff.</p><p>If I catch your interest, let me hear from you.<
/p></div></div>
<div><b>Published:</b> 12/11/2014 3:04 PM</div>
]]></description>
      <author></author>
      <pubDate>Thu, 11 Dec 2014 15:04:03 GMT</pubDate>
      <guid isPermaLink="true">http://servername/Test_Blog_B/Lists/Posts/ViewPost.as
px?ID=1</guid>
    </item>
  </channel>
</rss>* Connection #0 to host servername left intact
这是一个普通的SharePoint博客,安装在SharePoint 2013上。在浏览器中打开这个提要会得到与CURL相同的结果,所以我看不出我的C代码是如何被提供不同的服务的


感谢您提供的任何有关此原因的帮助,因此解决方案是CredentialCache.DefaultCredentials获取运行IIS服务器的凭据,而不是我自己的凭据。为代码提供我自己的凭据可以工作并提供预期的输出