2011-02-04 67 views
0

我正嘗試使用C#共享Google電子表格。由於Google Data 3.0 API尚未被移植到C#,我一直在嘗試與其RESTful Web服務進行交互。我之前沒有使用過REST。使用C#和REST共享Google電子表格

谷歌詢問以下:

POST /feeds/default/private/full/<resource_id>/acl HTTP/1.1 
Host: docs.google.com 
GData-Version: 3.0 
Authorization: <your authorization header here> 

<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gAcl='http://schemas.google.com/acl/2007'> 
    <category scheme='http://schemas.google.com/g/2005#kind' 
term='http://schemas.google.com/acl/2007#accessRule'/> 
    <gAcl:role value='writer'/> 
    <gAcl:scope type='user' value='[email protected]'/> 
</entry> 

我使用下面的代碼來嘗試訪問Web服務,但它不是爲我工作。鑑於上述要求,這段代碼是不正確的?

 HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest; 
     entry = bunchaxml; 
     request.Method = "POST"; 
     request.ContentType = "text/xml"; 
     request.Headers["GData-Version"] = "3.0"; 
     request.Credentials = new NetworkCredential(username, password); 
     using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) 
     { 
      writer.WriteLine(entry.ToString()); 
     } 
     try 
     { 
      HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
      string sc = response.StatusCode.ToString(); 
      string scd = response.StatusDescription.ToString(); 
     } 
     catch (Exception e) 
     { 
      //LogError 
     } 
+0

您使用的是什麼版本的.NET? – 2011-02-04 23:56:49

+0

如果您使用的是.NET 3.5或4.0,則應該可以使用WCF REST入門工具包。他們有一個HttpClient,它使訪問螞蟻REST服務變得非常簡單 – 2011-02-04 23:59:03

回答

相關問題