2014-12-19 54 views
0

我試圖連接到Sharepoint服務器並在C#中獲取RSS源。這似乎是一個足夠簡單的任務,但是由於某種原因,當我發送一個HttpWebRequest時,Sharepoint向我發送了一個不同的響應,這個響應與我在瀏覽器中訪問這個feed時得到的結果不同。具體來說,它返回沒有任何s的feed。HttpWebRequest從SharePoint服務器獲得不同於一切的響應

對提出請求的代碼如下:

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> 

然而,一切我嘗試得到這個響應(捲曲輸出,剪斷了一些標題爲簡潔起見)

* 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年打開該飼料中的瀏覽器提供同樣的結果捲曲,所以我不能看到的我的C#代碼被提供了不同的東西。

隨着這種情況的原因任何幫助表示讚賞,感謝

回答

0

因此,解決辦法是,CredentialCache.DefaultCredentials需要什麼運行IIS的服務器,這不是我自己的憑證的憑證。給代碼我自己的憑據工作,並給出預期的輸出。

相關問題