![](/img/trans.png)
[英]How to upload file to a team site on Sharepoint online (Office 365)
[英]How to connect Office 365 - SharePoint edition site using a external Rest web service made without using SharePoint?
我對SharePoint完全陌生。 我有一個不是使用SharePoint的Rest Web服務。 我可以使用此Rest Web服務連接SharePoint網站(Office 365-SharePoint版本)(如果是,那么如何實現它),還是需要使用SharePoint進行Rest服務?
如果有人可以幫助我,我將非常感激。 提前致謝。
有HttpWebRequest和HttpWebResponse類,使您可以調用REST服務。 之前,我曾使用它來訪問Parse.com(無法使用本機C#接口)等服務以及我自己的Web服務。 這是來自MSDN的示例:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]);
// Set some reasonable limits on resources used by this request
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;
// Set credentials to use for this request.
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
Console.WriteLine ("Content length is {0}", response.ContentLength);
Console.WriteLine ("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.WriteLine ("Response stream received.");
Console.WriteLine (readStream.ReadToEnd ());
response.Close ();
readStream.Close ();
您可以在此處找到更多信息: http : //msdn.microsoft.com/zh-cn/library/system.net.httpwebrequest.getresponse(v=vs.110).aspx
這是我用來為用戶獲取朋友的一段代碼示例:
public static WebExceptionStatus processResponse(HttpWebRequest response, out JsonValue values)
{
try
{
using (WebResponse stream = response.GetResponse())
{
using (StreamReader reader = new StreamReader(stream.GetResponseStream()))
{
values = JsonObject.Parse (reader.ReadToEnd ());
return WebExceptionStatus.Success;
}
}
}
catch (WebException exception) {
values = null;
return exception.Status;
}
}
...
HttpWebRequest request = HttpWebRequest.Create ("myURL") as HttpWebRequest;
request.Headers["SOMEH_HAEDER_VALUE"] = applicationID;
request.Method = "GET";
request.ContentType = "application/json";
JsonValue values;
status = RequestDriver.processResponse (request, out values);
if (RequestDriver.HadException (status)) {
ExceptionHandler.handleNetworkException(status);
}
if (values ["results"].Count == 0) {
return null;
}
JsonValue userValue = values ["results"] [0];
string name = RequestDriver.stripQuotes( userValue["Name"].ToString() );
string objectId = RequestDriver.stripQuotes( userValue["objectId"].ToString() );
User user = new User (name, email, objectId);
return user;
您可以在SharePoint中使用REST服務來訪問列表和列表項之類的數據。 http://msdn.microsoft.com/library/office/dn292552.aspx
您將需要獲取訪問令牌以添加到請求中的Authorization標頭中。 若要獲取請求的令牌,必須在Azure Active Directory中注冊您的應用程序。 本文介紹了如何執行此操作http://msdn.microsoft.com/zh-cn/library/office/dn605894(v=office.15).aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.