2016-07-07 15 views

回答

-1

对于使用C#中的SoftLayer,有可用的下一个环节:

https://sldn.softlayer.com/article/C-Sharp

下一个环节提供对象存储信息REST:

http://sldn.softlayer.com/blog/waelriac/managing-softlayer-object-storage-through-rest-apis

下是一个例子如何使用C#与SoftLayer API进行交互。该示例在前面的C#链接之后。

using System; 
using Newtonsoft.Json; 

namespace GetHubNetworkStorage 
{ 
    class Program 
    { 
    static void Main(string[] args) 
    { 
     string username = "set me";   
     string apiKey = "set me"; 

     authenticate authenticate = new authenticate(); 
     authenticate.username = username; 
     authenticate.apiKey = apiKey; 

     SoftLayer_AccountService accountService = new SoftLayer_AccountService(); 
     accountService.authenticateValue = authenticate; 

     try 
     { 
     // The result is an array of SoftLayer_Network_Storage objects and can be either iterated 
     // one by one to use the data or being displayed as a JSON value such in this example. 
     var hubNetworkStorages = accountService.getHubNetworkStorage(); 
     string json = JsonConvert.SerializeObject(hubNetworkStorages, Formatting.Indented); 
     Console.WriteLine(json); 
     } 
     catch (Exception e) 
     { 
     Console.WriteLine("Can't retrieve SoftLayer_Network_Storage information: " + e.Message); 
     } 
     Console.ReadKey(); 
    } 
    } 
} 

下一个环节,如果你决定要设法通过卷曲的对象存储REST的API,但裹成C#代码还可以帮助你:

Making a cURL call in C#

0

谢谢,非常感谢 - 的下一部分任务是将Android设备上的文件上传到对象存储。代码有点(!)凌乱,缺少错误检查,但希望能指出其他人试图在正确的方向上做到这一点。

var path = Android.OS.Environment.ExternalStorageDirectory ; 
var filename = path + Java.IO.File.Separator + string.Format("{0}", prefix) + "mydata.txt"; 
string username = "SLOS1234567-1:SL1234567"; 
string apiKey = "1234567891234567891234567891234567891234567891234567891234567891"; 
string tokenval, URLval, URLcomp; 

//Create a web request for authentication. 
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("https://syd01.objectstorage.softlayer.net/auth/v1.0"); 

//Get the headers associated with the request. 
WebHeaderCollection myWebHeaderCollection = myHttpWebRequest.Headers; 

//Add the X-Auth-User header (for OS user) in the request. 
myWebHeaderCollection.Add("X-Auth-User", username); 

//Add the X-Auth-Key header (for the API key) in the request. 
myWebHeaderCollection.Add("X-Auth-Key",apiKey); 

//Get the associated response - the auth token and storage URL. 
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 

tokenval = myHttpWebResponse.GetResponseHeader("X-Auth-Token"); 
URLval = myHttpWebResponse.GetResponseHeader("X-Storage-Url"); 
URLcomp = URLval + "/mycontainer/myDirectory/" + string.Format("{0}", prefix) + "mydata.txt"; 

//Upload the file 
WebClient wc = new WebClient(); 
wc.Headers.Add("X-Auth-Token",tokenval); 
wc.UploadFile(URLcomp, "PUT", filename); 
相关问题