3
我需要使用本地服務來使用生成的XML文檔流。雖然終點本身不是REST服務。我想確保下面概述的方法是將響應返回到XDocument
的最有效方法。檢索HttpWebResponse並將其放入XDocument的有效方法
Uri requestUri = null;
Uri.TryCreate(String.Format(SearchAddress, filter),
UriKind.Absolute, out requestUri);
NetworkCredential nc =
new NetworkCredential("Login", "Password");
CredentialCache cCache = new CredentialCache();
cCache.Add(requestUri, "Basic", nc);
HttpWebRequest request =
(HttpWebRequest)HttpWebRequest.Create(requestUri);
request.Credentials = cCache;
request.PreAuthenticate = true;
request.Method = WebRequestMethods.Http.Get;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
XDocument xDoc =
XDocument.Load(new StreamReader(response.GetResponseStream()));
有關處理'WebException'好主意。也就是說,對於異步請求,您的修改建議是什麼? – ahsteele 2009-12-08 21:45:08